htaccess 301 重定向,如何正确执行
htaccess 301 redirect, how to do it properly
我想将我的旧网站重定向为我的新网站的目录。
olddomain.tld = 新域名。tld/directory/
重定向 301 / https://newdomain.tld/directory/
但是当我设置
重定向 301 /contactus/ https://newdomain.tld/contact-us/
结果是 https://newdomain.tld/directory/contact-us/ 404,因为路径错误。
如何解决这个问题?
此致
我建议您避免 Redirect
并使用更强大的 mod_rewrite
引擎。
您可以在旧主机的 .htaccess 上使用这些规则:
RewriteEngine On
RewriteRule ^contactus/(.*)$ https://newdomain.tld/contact-us/ [L,NC,R=301,NE]
RewriteRule ^(.*)$ https://newdomain.tld/directory/ [L,NE,R=301]
确保清除浏览器缓存。
参考文献:
我想将我的旧网站重定向为我的新网站的目录。
olddomain.tld = 新域名。tld/directory/
重定向 301 / https://newdomain.tld/directory/
但是当我设置 重定向 301 /contactus/ https://newdomain.tld/contact-us/ 结果是 https://newdomain.tld/directory/contact-us/ 404,因为路径错误。
如何解决这个问题?
此致
我建议您避免 Redirect
并使用更强大的 mod_rewrite
引擎。
您可以在旧主机的 .htaccess 上使用这些规则:
RewriteEngine On
RewriteRule ^contactus/(.*)$ https://newdomain.tld/contact-us/ [L,NC,R=301,NE]
RewriteRule ^(.*)$ https://newdomain.tld/directory/ [L,NE,R=301]
确保清除浏览器缓存。
参考文献: