Apache Mod 重写 - 用另一个替换:字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1345314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache Mod Rewrite - Replace : character with another
提问by mikeytown2
I'm trying to rewrite all URL's that contain a ':' in it to another character. http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
我正在尝试将所有包含 ':' 的 URL 重写为另一个字符。 http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
Example:
例子:
http://example.com/some_interesting:info
http://example.com/some_interesting_info
http://example.com/some:interesting:info
http://example.com/some:interesting_info
would all point to this file
都会指向这个文件
some_interesting_info
How can I do this?
我怎样才能做到这一点?
EDIT: Did more testing
编辑:做了更多的测试
this works
这有效
RewriteRule ^(.*)_(.*) [L]
RewriteRule ^(.*)\_+(.*) [L]
test_rewrite.html goes to testrewrite.html
test_rewrite.html 转到 testrewrite.html
this doesn't
这不
RewriteRule ^(.*):(.*) [L]
RewriteRule ^(.*)\:+(.*) [L]
test:rewrite.html gives a 403
test:rewrite.html 给出 403
In terms of eliminating the character in the middle. Tested with xammp 1.7.1
在消除中间字符方面。使用 xampp 1.7.1 测试
回答by Gumbo
Try these rules:
试试这些规则:
RewriteRule ^/([^:]*):([^:]*:.*) /_ [N]
RewriteRule ^/([^:]*):([^:]*)$ /_
回答by Taylor Leese
Here's a link to RewriteRule.
这是RewriteRule的链接。
RewriteRule ^/some[_:]interesting[_:]info$ /some_interesting_info [L]

