开发者

Need to redirect to true root folder

开发者 https://www.devze.com 2022-12-31 05:18 出处:网络
I am running a website on MAMP, and the root is http://localhost/sandbox When I have links that link to, for example - /calendar

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号