2012-03-01 68 views
0

我的.htaccess文件是,由於某種原因,導致500內部服務器錯誤,當我試圖重定向這樣的子域:子域名重定向與htaccess以及一個500內部服務器錯誤

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC] 
RewriteRule ^(.*)$ folder/anotherfolder/$1 [L] 

我目前的主機不會自己重定向子域名,所以我必須這樣做。我試圖實現的是,當用戶輸入http://subdomain.domain.com/時,他確實看到http://domain.com/folder/anotherfolder。但是,我不想讓地址欄上的域自己改變。子域本身顯然是主域的別名,因此指向與主域相同的文件夾。

上面的代碼也工作時,正則表達式導致它用作GET,因爲這樣的:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC] 
RewriteRule ^(.*)$ folder/anotherfolder/index.php?p=$1 [L] 

的GET「P」的值,然而,這不是例如「test.php」(如果你試圖訪問subdomain.domain.com/test.php),但是從主域(即folder/anotherfolder/test.php)的整個路徑。

任何想法我做錯了什麼?

回答

2

啊,似乎是由內部重定向循環造成的。通過這樣做,固定:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC] 
RewriteRule ^folder/anotherfolder/ - [L] 
RewriteRule (.*) folder/anotherfolder/$1 [L] 

有趣的是,答案通常在你問別人之後就會顯示出來。

1

你的代碼改成這樣:

RewriteEngine On 

RewriteCond %{QUERY_STRING} !^p= [NC] 
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC] 
RewriteRule ^(.*)$ folder/anotherfolder/index.php?p=$1 [L]