2011-03-29 139 views
0

我读了.htaccess rewrite to redirect root URL to subdirectory,我试图达到同样的目的。重定向到另一个文件夹

与大多数选票的解决方案是:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example\.com$ 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 
RewriteRule ^$ store [L] 

现在,看评论,似乎是工作好。 问题是我不想硬编码任何路径(而不是上面提供的“www.example.com”)。我希望我的.htaccessprojectname/之内重定向到projectname/public/,尽管真正的服务器主机是什么。因此,如果我将projectname/放入根服务器www.pinco.com内,它将重定向到www.pinco.com/projectname/public/,但它显示的是www.pinco.com/projectname/

我该如何做到这一点?

回答

0

您发现的例子实际上是在做两件不同的事情。

# This is actually just redirecting all http://example.com/somepage/ 
# to http://www.example.com/somepage/, to ensure all URLs have the www. 
RewriteCond %{HTTP_HOST} ^example\.com$ 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

第二次重写是帮助你实现你想要做的事情。

# This redirect all requests for http://example.com -> http://example.com/newdir 
# If you are looking to redirect the request, so the URL contains directory name, 
# you can change the [L] to [R=301,L] 
RewriteRule ^$ /newdir [L] 

# If your concerned about direct access to a particular page without the sub-dir 
# you will want to add something like this 
RewriteCond %{REQUEST_URI} !^/newdir 
RewriteRule (.*) /newdir$1 [R=301,L] 

因此,在这种情况下,您不必关心运行应用程序的域。

0

尝试添加此行,:

RewriteBase /projectname 

你留在项目中。

相关问题