Chris
Chris

Reputation: 59541

.htaccess rewrite with subdirectory

I want to rewrite (not redirect) all url's of my site to a sub-directory of my site. For example:

http://example.com/example

would load the following:

http://example.com/public/example

Though, requesting http://example.com/public should not load the contents from public/public but from /.

Answers I've found on SO either do the above with redirect (which I don't want) or doesn't account for the special case above.

EDIT: further clarification:

I want every request on my site to go load under the public folder, but without being visible to the visitor. So requesting http://example.com/index.php will load the file from http://example.com/public/index.php. The url in the browser remains unchanged for the user.

Upvotes: 2

Views: 52

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

Try the following rule :

RewriteEngine on

RewriteRule ^((?!public).+)$ /public/$1 [NC,L]

This will rewrite all requests from root to /public dir.

Upvotes: 1

Related Questions