URL rewrite (Apache) hide folder
I have some problems rewriting the URL of a website.
The folder structure I got is basically
public_html
-farms
-public
-functions
So basicly what I want is to turn URLs like:
www.site.com/farms/public/pageInPublicFolder.php INTO www.site.com/farms/pageInPublicFolder.php
So if I do something like site.com/farms/index.php it should take the index file that's in the public folder, but hide the fact that's inside the public folder from the URL.
By looking at other threads here at the site I've found the following code:
RewriteEngine On
RewriteRule ^/(.*)$ /public/$1
I've placed the above code in a .htaccess file in the farms folder, how开发者_开发问答ever i just get a 404 trying to access any of the files. Any help?
First, whenever you use a RewriteRule
in .htaccess, the matched string will never start with a slash character. So, your rule never matches.
After that, though, you need to ensure that you do not keep applying the rule recursively, because the rules all get run again after a rewrite (at least in per-directory context). So, what you actually want is something like:
RewriteEngine on
RewriteBase /home/yourdirectory/public_html
RewriteCond %{REQUEST_FILENAME} !public
RewriteRule ^farms/(.*)$ public/$1 [L]
Double-check whether this works in your scenario, and if not, post your error from your Apache log so I can help fix it, if you would like.
精彩评论