htaccess重写cond重写URL排除404错误

我有我的.htaccess文件的这个问题。

Google在网站站长工具中有一些我不想要的url(404错误)。

我需要重写包含--/-或结尾的url,例如:

  1. replace---
  2. 删除-/
  3. 删除结尾-

…但只有当URL不包含product_info.php

我尝试过,但它不工作…

 RewriteCond %{REQUEST_URI} !^/product_info\.php(.*)$ RewriteRule ^(.*)--(.*)$ /$1-$2 [L,R=301] RewriteRule ^(.*)/-(.*)$ /$1/$2 [L,R=301] RewriteRule ^(.*)-$ /$1$2 [L,R=301] 

这是一个Magento电子商店与激活清漆caching。

编辑#1:

是的,他们出现在404错误报告!

不工作我的意思是:Magento说:“这个文件已经搬到这里”。 如果我点击那里,有一个“ESI块错误”

product_info.php?product=TestProduct--Green--XXL之后可以有东西

在这种情况下,我不想replace-- - = - >这是我想的问题。

编辑#2:

这是完整的.htaccess 。 我删除了评论期望redirect我试图得到工作,因为很多的空间。

 DirectoryIndex index.php <IfModule mod_php5.c> php_value memory_limit 6144M php_value max_execution_time 18000 php_flag magic_quotes_gpc off php_flag session.auto_start off php_flag suhosin.session.cryptua off php_flag zend.ze1_compatibility_mode Off </IfModule> <IfModule mod_security.c> SecFilterEngine Off SecFilterScanPOST Off </IfModule> <IfModule mod_deflate.c> </IfModule> <IfModule mod_ssl.c> SSLOptions StdEnvVars </IfModule> <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} ^/rma/ RewriteRule ^ - [L] #RewriteCond %{REQUEST_URI} !^/product_info(.*) #RewriteRule ^(.*)--(.*)$ /$1-$2 [L,R=301] #RewriteCond %{REQUEST_URI} !^/product_info(.*) #RewriteRule ^(.*)/-(.*)$ /$1/$2 [L,R=301] #RewriteCond %{REQUEST_URI} !^/product_info(.*) #RewriteRule ^(.*)-$ /$1$2 [L,R=301] RewriteRule ^api/rest api.php?type=rest [QSA,L] RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_METHOD} ^TRAC[EK] RewriteRule .* - [L,R=405] RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule .* index.php [L] </IfModule> AddDefaultCharset Off <IfModule mod_expires.c> ExpiresDefault "access plus 1 year" </IfModule> Order allow,deny Allow from all <Files RELEASE_NOTES.txt> order allow,deny deny from all </Files> <Files cron.php> Order allow,deny Deny from all </Files> 

RewriteCond指令只适用于RewriteRule单个 RewriteRule 。 所以,你需要为每个规则重复这个条件。 例如:

 Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI} !^/product_info\.php RewriteRule (.*)--(.*) /$1-$2 [L,R=301] RewriteCond %{REQUEST_URI} !^/product_info\.php RewriteRule (.*)/-(.*) /$1/$2 [L,R=301] RewriteCond %{REQUEST_URI} !^/product_info\.php RewriteRule (.*)-$ /$1 [L,R=301] 

或者,您可以在规则的开始处包含一个例外,以避免重写/product_info.php文件。 但是这取决于你的.htaccess文件的其余部分,因为它会将/product-info.php排除在外。 例如:

 RewriteRule ^product_info\.php$ - [L] 

我也删除了CondPattern的尾部(.*)$ – 在这个例子中是多余的。 当你有一个cacth-all .*模式(默认为贪婪)的时候也是如此。

在testing之前确保你所有的caching都清除了。 使用302 (临时)redirecttesting通常比较容易,因为这些redirect不是(或不应该)被caching。