.htaccess - 如何使用问号和标签重定向或重写 url?
问题描述
我会通过.htaccess
文件将以前的站点 URL 重定向或重写到相关的新站点 URL。
由于其他一些原因,这已经在.htaccess
文件中,下面的代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我想重定向或重写如下:
http://www.example.com/index.php?pages/oldpage#part
至
http://www.example.com/newpage/
要进行此重定向或重写,我不知道要在.htaccess
文件中添加什么?
解决方案
RewriteCond %{QUERY_STRING} ^pages/oldpage$
RewriteRule ^index\.php /newpage [QSD]
- 使用仅
RewriteCond
匹配从开始到结束的查询字符串来捕获查询字符串。pages/oldpage
- 用于
RewriteRule
匹配您的,REQUEST_URI
然后将其重定向到使用QSD有效地丢弃查询字符串的位置。index.php
http://www.example.com/index.php?pages/oldpage
/newpage
http://www.example.com/newpage
推荐阅读
- ios - 如何将 iOS 项目从 Kony Visualizer 导出并运行到 Xcode?
- excel - 我需要从各种工作簿中的不同工作表中提取修订。每个文档都有不同数量的修订,我该怎么做?
- elasticsearch - 弹性搜索日期范围过滤器 lambda 表达式问题
- javascript - 通过 babel-register 动态导入导致多余的“默认模块”
- python-3.x - 在 tensorflow 中使用 DNNLinearCombinedEstimator 进行多标签分类
- c# - 如何在 EntityFramework 中配置这种关系(1 -> many, plus 1 -> 0 or 1, no join table)
- recursion - 我的 Bytelandian 金币问题 CodeChef 解决方案中的问题是什么?
- php - Wordpress - 使用 Ajax 分页按最高帖子浏览量列出的顶级作者列表
- openshift - 在 OpenShift 中以声明方式挂载服务帐户密钥
- php - 标注在 stdClass 中创建的字段?