Brighton Vino
Brighton Vino

Reputation: 395

Hiding a Sub Directory in URL

Inside public_html directory I have a folder myfolder and I have the index.php in that folder.

All my site url reads

http://example.com/myfolder/page-name

I want it to rewritten as

http://example.com/page-name

What rule should I write in .htaccess to achieve the same

Upvotes: 3

Views: 7062

Answers (2)

Olivier Pons
Olivier Pons

Reputation: 15796

Here's what should work:

RewriteEngine On
RewriteRule /?myfolder/(.*) $1 [QSA,L]

The following sample does this: if we try to access something that doesn't start by /myfolder, then add /myfolder into the URL:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/myfolder
RewriteRule (.*) /myfolder/$1 [QSA,L]

Upvotes: 3

Jon Lin
Jon Lin

Reputation: 143906

In your public_html directory's .htaccess file, add these rules:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/myfolder
RewriteRule ^/?([^/]+)$ /myfolder/$1 [L]

Upvotes: 4

Related Questions