2014-11-06 45 views
1

我有這樣的代碼重寫的路徑,然後重定向到子域的文件夾的路徑:的.htaccess重寫路徑:新查詢字符串刪除第一個斜線

RewriteEngine On 
RewriteBase/

RewriteRule ^category/?$ category.php 
RewriteRule ^category/[a-z0-9\-]+\_([A-Z0-9\_]+)/?$ articles.php?id=$1&section=category 

RewriteCond %{HTTP_HOST} ^test.(.*)example.com/?$ [NC] 
RewriteCond %{REQUEST_URI} !^/\!test/ [NC] 
RewriteRule (.*) /!test/$1 [L,NC] 

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

最大的問題是,在瀏覽器中鍵入此地址字段,然後按Enter:

http://test.example.com/category/article-about-something_35436 

結束了,因爲它本身更改爲:

http://test.example.comcategory/article-about-something_35436 

而瀏覽器當然會告訴你「找不到服務器」。

故障排除

我已經想通了,這工作得很好:

http://test.example.com/category 

而且從第二重寫規則去除查詢字符串?id=$1&section=category工作。當然,你不會在文章結尾,但在articles.php

那麼,有誰知道這個問題?

+0

打開Firebug,並參觀'HTTP:// test.example.com /分類/條,約-something_35436'在瀏覽器。現在看看你在'Net'選項卡中得到了什麼重定向。 – anubhava 2014-11-06 20:10:02

+0

沒有什麼,只是空的。但在Chrome的開發人員工具的網絡部分中發生了一些事情。但是我看不到任何能告訴我該怎麼做的事情。我看到一個「301永久移動」。 – 2014-11-06 20:21:11

+0

當你得到301的時候,它被重定向到了什麼地方?此外,你的代碼沒有任何301 – anubhava 2014-11-06 20:25:08

回答

0

重新安排你的規則,並使用重定向規則與之前其他內部重寫規則R標誌:

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteRule ^category/?$ category.php [L,NC] 

RewriteRule ^category/[a-z0-9-]+_([A-Z0-9_]+)/?$ articles.php?id=$1&section=category [L,QSA] 

RewriteCond %{HTTP_HOST} ^test\.(.*)example\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/\!test/ [NC] 
RewriteRule (.*) /!test/$1 [L,NC] 
+0

仍然不能正常工作,發生同樣的事情:/ – 2014-11-06 21:14:02

+1

您是否在Chrome瀏覽器開發工具中測試了在瀏覽器中輸入URL爲「http:// test.example.com/category/article-about-something_35436」?您的規則中沒有該網址的301個 – anubhava 2014-11-06 21:15:52

+0

是的,我做過。不,沒有。這就是爲什麼這很奇怪。 :/ – 2014-11-06 21:26:29

相關問題