use*_*643 3 .htaccess mod-rewrite query-string http-status-code-301
我有一些凌乱的旧网址,比如......
http://www.example.com/bunch.of/unneeded/crap?opendocument&part=1
http://www.example.com/bunch.of/unneeded/crap?opendocument&part=2
...我想重定向到更新,更清洁的形式......
http://www.example.com/page.php/welcome
http://www.example.com/page.php/prices
我知道我可以通过简单的重定向将一个页面重定向到另一个页面,即
重定向301 /bunch.of/unneeded/crap http://www.example.com/page.php
但源页面不会改变,只有它是GET变量.我无法弄清楚如何将重定向基于这些GET变量的值.任何人都可以帮忙!?我对旧的正则表达方式非常方便,所以如果必须的话我可以使用mod-rewrite,但是我不清楚重写GET变量的语法,我宁愿避免性能损失并使用清除Redirect指令.有办法吗?如果没有,任何人都可以提出正确的mod-rewrite语法?
干杯,
罗杰.
由于URL查询中的参数可能具有任意顺序,因此您需要为每个参数使用一个RewriteCond指令来检查或每个可能的permtiation.
这是一个带有RewriteCond每个参数指令的示例:
RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=1(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/welcome? [L,R=301]
RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=2(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/prices? [L,R=301]
Run Code Online (Sandbox Code Playgroud)
但正如你所看到的,这可能会变得一团糟.
所以更好的方法可能是使用a RewriteMap.最简单的是具有键和值对的纯文本文件:
1 welcome
2 prices
Run Code Online (Sandbox Code Playgroud)
要定义映射,请在服务器或虚拟主机配置中编写以下指令(在每个目录上下文中不允许使用此指令):
RewriteMap examplemap txt:/path/to/file/map.txt
Run Code Online (Sandbox Code Playgroud)
那你只需要一条规则:
RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=([0-9]+)(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/%{examplemap:%2}? [L,R=301]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12976 次 |
| 最近记录: |