在htaccess文件中正确使用重定向

问题描述 投票:0回答:1

我需要在新网站(https://myweb/)的相应页面中从旧网站(https://myweb/new)重定向访问。因此,我更改了https://myweb/.htaccess文件:

Redirect 301 /contact https://myweb/new/contact-us
Redirect 301 /blog https://myweb/new/my-blog
....

我认为重定向的工作方式如if然后退出:

if page is "/contact" then open https://myweb/new/contact-us and exit

在这些行之后,我编写了一些代码来重定向“其他”陈述中的请求:

RewriteRule (.*) https://myweb/new/ [R=301,L]

这是正确的解决方案吗?

apache .htaccess redirect
1个回答
0
投票

具有这种方式:

RewriteEngine On

RewriteRule ^contact(.*)$ /new/contact-us$1 [L,NC,R=301]

RewriteRule ^blog(.*)$ /new/my-blog$1 [L,NC,R=301]

RewriteRule !^new/ /new%{REQUEST_URI} [L,NC,R=301]

清除浏览器缓存后,请务必进行测试。

© www.soinside.com 2019 - 2024. All rights reserved.