apache - 在 htaccess 文件中正确使用重定向
问题描述
我需要在新网站 ( https://myweb/new )的相应页面中重定向来自旧网站 ( https://myweb/ ) 的访问。所以我改变了我的https://myweb/.htaccess文件:
Redirect 301 /contact https://myweb/new/contact-us
Redirect 301 /blog https://myweb/new/my-blog
....
我认为重定向的工作方式类似于 if then exit:
if page is "/contact" then open https://myweb/new/contact-us and exit
在这些行之后,我编写了一些代码来重定向“else”语句中的请求:
RewriteRule (.*) https://myweb/new/ [R=301,L]
这是正确的解决方案吗?
解决方案
有这种方式:
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]
确保在清除浏览器缓存后进行测试。
推荐阅读
- docker - 在 PhpStorm 中附加 Vagrant 托管的 Gremlin-Server 作为数据源
- html - 在 JQuery 中的 AJAX 之前执行 for 循环
- java - Java 如何设置它的路径以及如何更改它?
- java - LeetCode 231:找出给定数字是否为 2 的幂的问题
- string - SQL根据最新日期文本值聚合文本字段
- vector - 应该使用什么 CALayer draw(in ctx:) 坐标以正确的比例在正确的点上绘制?
- javascript - 在反应js中更新对象数组中的值
- javafx - JavaFX 不是 JDK 14 的一部分
- swift - 更新我的 UI 时的 Firestore 侦听器最佳实践
- rust - 没有移动的 rust pass 框参考