.htaccess HTACCESS 301重定向继续发送到错误页面
我正试图将一个我重新设计的网站的旧页面重定向到新页面,但它不起作用 以下是我在.htaccess HTACCESS 301重定向继续发送到错误页面,.htaccess,redirect,mod-rewrite,mod-alias,.htaccess,Redirect,Mod Rewrite,Mod Alias,我正试图将一个我重新设计的网站的旧页面重定向到新页面,但它不起作用 以下是我在.htaccess文件中关于该域的两行代码: Redirect 301 /deaneco http://solutionsgtr.ca/fr/deaneco/accueil.html RewriteRule ^/deaneco/contact http://solutionsgtr.ca/fr/deaneco/contact.html [R=301,L,QSA] 如果进入solutionsgtr.ca/deaneco
.htaccess
文件中关于该域的两行代码:
Redirect 301 /deaneco http://solutionsgtr.ca/fr/deaneco/accueil.html
RewriteRule ^/deaneco/contact http://solutionsgtr.ca/fr/deaneco/contact.html [R=301,L,QSA]
如果进入solutionsgtr.ca/deaneco/contact
URL,它将显示以下页面:
http://solutionsgtr.ca/fr/deaneco/accueil.html/contact
第一条规则仍然有效(deaneco/
到solutionsgtr.ca/fr/deaneco/acueil.html
)
我觉得这两行代码混合在一起,给了我错误的页面,这是不存在的,所以我得到了404错误。这里有几个问题:
指令(mod_别名的一部分)是前缀匹配,匹配后的所有内容都附加到目标URL的末尾。这解释了您看到的重定向Redirect
(mod_rewrite)模式RewriteRule
在^/deaneco/contact
上下文中永远不会匹配,因为匹配的URL路径不是以斜杠开头的。所以,这条规则目前没有任何作用.htaccess
Redirect 301 /deaneco/contact http://solutionsgtr.ca/fr/deaneco/contact.html
Redirect 301 /deaneco http://solutionsgtr.ca/fr/deaneco/accueil.html
注意:您需要清除浏览器缓存,因为错误的301(永久)重定向将被浏览器缓存。使用302(临时)重定向进行测试,以避免潜在的缓存问题
或者,如果您已经使用MODY重写用于其他重定向/重写,那么考虑使用MODY-Read来代替(避免上面提到的潜在冲突):
QSA
标志不是必需的,因为默认情况下查询字符串传递给替换
在本例中,RewriteRule
指令的顺序并不重要,因为它们只匹配特定的URL
如果需要,请访问
解决方案gtr.ca/deaneco/contact
URL
如果要重定向到同一主机,则不需要在目标URL中显式包含scheme+主机名,因为这将是默认设置。非常感谢,第二个代码段工作正常。再次感谢您详细解释一切。
RewriteEngine On
RewriteRule ^deaneco/contact$ http://solutionsgtr.ca/fr/deaneco/contact.html [R=301,L]
RewriteRule ^deaneco$ http://solutionsgtr.ca/fr/deaneco/accueil.html [R=301,L]