使用htaccess将所有404错误(不包括特定的404 URL)重定向到主页



我目前正在翻新我的网站,该网站有1000个页面;这需要更改url。

  1. 我想301永久重定向所有404错误到网站主页说www.domain.com,除了一些特定的404网址
  2. 我想301永久重定向那些特定排除的404 URL(在1号)到另一个URL

我尝试了以下代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/about-us0.html [NC]
RewriteCond %{REQUEST_URI} !^/contact_us0.html [NC]
RewriteRule ^(.*)$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^about-us0.html$ "http://www.domain.com/about.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^contact-us0.html$ "http://www.domain.com/contact.html" [R=301,L]

但当我浏览到www.domain.com/about-us0.html或www.domain.com/contact_us0.html时;googlechrome表示"这个网页有一个重定向循环"。

我做错什么了吗?任何帮助都将不胜感激。


用于重定向而不携带查询字符串:

http://domain.com/prod/species.php?action=3&file_id=30

http://domain.com/species-30.php

http://domain.com/prod/species.php?action=3&file_id=101

http://domain.com/species-101.php

我做了这样的事情(下面),效果很好。这里面需要什么改变吗?

RewriteCond %{QUERY_STRING} ^action=3&file_id=([0-9]+)$ [NC]
RewriteRule ^prod/species.php$ /species-%1.php? [R=301,L]

试试这些规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(about|contact).*?.html [NC]
RewriteRule ^ / [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(contact|about)-us0.html$ http://www.domain.com/$1.html [R=301,L,NC]

最新更新