2013-07-02 51 views
1

這是我在.htaccess文件規則:301重定向使用的.htaccess不起作用

Redirect 301 /George-Nelson-Bench-CT3005-EDI6.htm?categoryId=-1 http://www.mydomain.com/proddetail.php?prod=George_Nelson_Bench 

但是,這顯示在我的網站404錯誤。

的.htaccess文件的一些其他代碼:

RewriteEngine On 

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

RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

一些其他301重定向其正常工作:

Redirect 301 /Modern-Classics_c8.htm http://www.mydomain.com/categories.php?cat=10 
Redirect 301 /Sofas_c34.htm http://www.mydomain.com/products.php?cat=25 
Redirect 301 /Bedroom_c2.htm http://www.mydomain.com/categories.php?cat=7 

那麼,爲什麼第301重定向規則不工作?
有什麼建議嗎?

+0

http://httpd.apache.org/docs/2.2/en/mod/mod_alias.html#redirect:'語法:Redirect [status] URL路徑URL ... ...這裏的重要部分:URL _path_ – CBroe

+0

@CBroe是的。規則中_URL-path_是正確的。沒有? – Debiprasad

+1

查詢字符串是_not_ URL路徑的一部分。 – CBroe

回答

1

由於您無論如何都使用mod_rewrite更好地將基於mod_alias的代碼替換爲更加強大和靈活的mod_rewrite。

您首先重定向規則不起作用,因爲您正在使用查詢參數。將此規則替換爲:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+George-Nelson-Bench-CT3005-EDI6\.htm\?categoryId=-1\s [NC] 
RewriteRule^/proddetail.php?prod=George_Nelson_Bench? [R=301,L] 
+0

謝謝你指出查詢字符串在這裏產生問題。我刪除它,現在它工作正常。我沒有使用mod_rewrite。謝謝。 – Debiprasad

+0

不客氣,很高興你的工作。 – anubhava