2011-03-29 136 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 

你留在項目中。

相關問題