I am running a website on MAMP, and the root is http://localhost/sandbox
When I have links that link to, for example - /calendar
it directs them to loca开发者_如何学JAVAlhost/calendar, I want it to redirect to localhost/sandbox/calendar
What would I have to do in htaccess to get it to redirect everything to localhost/sandbox/ as the root?
You would usually change the application or site that generates the links, and have that add the /sandbox
to the URL.
If that's not possible, putting this into the web root directory (the one above /sandbox
) should do:
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_URI} !^/sandbox # If URL does not start with /sandbox...
RewriteRule (.*) /sandbox/$1 # Add /sandbox/ in front of it
(if it's easier to achieve with Alias
, Apache Gurus, feel free to add your solution, but I couldn't get Alias to work for this scenario.)
However, this solution will make any other directory besides /sandbox
inaccessible. You may want to re-think your Virtual hosts structure!
精彩评论