Apache Mod Rewrite - Replace : character with another

痞子三分冷 提交于 2019-12-19 04:04:23

问题


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

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 ^(.*)_(.*) $1$2 [L]
RewriteRule ^(.*)\_+(.*) $1$2 [L]

test_rewrite.html goes to testrewrite.html

this doesn't

RewriteRule ^(.*):(.*) $1$2 [L]
RewriteRule ^(.*)\:+(.*) $1$2 [L]

test:rewrite.html gives a 403

In terms of eliminating the character in the middle. Tested with xammp 1.7.1


回答1:


Try these rules:

RewriteRule ^/([^:]*):([^:]*:.*) /$1_$2 [N]
RewriteRule ^/([^:]*):([^:]*)$ /$1_$2



回答2:


Here's a link to RewriteRule.

RewriteRule ^/some[_:]interesting[_:]info$ /some_interesting_info [L]


来源:https://stackoverflow.com/questions/1345314/apache-mod-rewrite-replace-character-with-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!