.htaccess - 在 htaccess 中使用 Rewriterule 的问题
问题描述
使用 RewriteRule 我总是按如下方式清理我的 URL:
RewriteRule ^page/(.*)$ page.php?urlkey=$1 [QSA]
我的新主机不允许我使用 Options +FollowSymLinks,因此我不能再使用 /。因此,我将 RewriteRule 更改为:
RewriteRule ^page-(.*)$ page.php?urlkey=$1 [QSA]
但是,我需要将所有以前的 URL 重定向到新版本。我尝试使用以下规则执行此操作:
RewriteRule ^page/(.*)$ page-(.*)$ [R=301,L]
然而,这是行不通的。我还尝试在我的 .htaccess 中进行重定向:
Redirect 301 https://www.example.com/page/urlkey https://www.example.com/page-urlkey
这也行不通。
编辑
根据要求,下面的实际代码:
RewriteEngine on
RewriteRule ^citywalk-(.*)$ citywalk.php?urlkey=$1 [QSA]
RewriteRule ^citywalk/(.*)$ citywalk-(.*)$ [R=301,L]
例如 citywalk The Historical Center 有一个 urlkey the-historical-center。旧网址是 citywalk/the-historical-center。
要测试此特定案例和其他技术:
Redirect 301 /citywalk/the-historical-centre https://example.com/citywalk-the-historical-centre
通过访问https://example.com/citywalk/the-historical-centre不会发生重定向(浏览器中的 url 保持不变)并且没有找到 urlkey。
解决方案
推荐阅读
- simple-injector - 简单注入器 .NET 标准 NuGet 包 PDB
- javascript - 绘制的多边形不显示在 openlayers
- ember.js - 未刷新页面未重新加载模型的 Ember 列表
- sql - MS Access 2010 - Access 中的第一个函数 SQL 是什么
- python - 将列表元素作为分隔字符串传递给 django 方法
- c++ - 特化模板化数据类型的模板
- automation - 如何使用 botium asserter 为使用 watson 开发的聊天机器人使用超链接断言?
- apache - 如何检测我的服务是否使用 SSL 或 TLS 以及哪个版本
- asp.net-mvc - 现有 .NET Core MVC 解决方案中的 Angular 不起作用
- ios - 如何在 iOS 上编辑 NativeScript-Angular RadDataForm UIStepper?