需要重定向到真正的根文件夹

时间:2010-05-24 15:39:08

标签: .htaccess

我在MAMP上运行一个网站,根目录是http://localhost/sandbox

当我有链接到的链接时,例如 - / calendar

它将它们定向到localhost / calendar,我希望它重定向到localhost / sandbox / calendar

我需要在htaccess中做些什么来让它将所有内容重定向到localhost / sandbox /作为root?

1 个答案:

答案 0 :(得分:2)

您通常会更改生成链接的应用程序或网站,并将/sandbox添加到网址。

如果无法做到这一点,请将其放入网络根目录(/sandbox上方的那个):

RewriteEngine on
Options +FollowSymlinks

RewriteCond  %{REQUEST_URI} !^/sandbox  # If URL does not start with /sandbox... 
RewriteRule (.*) /sandbox/$1            # Add /sandbox/ in front of it

(如果使用Alias更容易实现,Apache Gurus可以随意添加您的解决方案,但我无法让Alias在这种情况下工作。)

但是,此解决方案将使/sandbox以外的任何其他目录无法访问。您可能想要重新考虑虚拟主机结构!

相关问题