Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Mod Rewrite - Replace : character with another

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

like image 246
mikeytown2 Avatar asked Sep 04 '26 14:09

mikeytown2


1 Answers

Try these rules:

RewriteRule ^/([^:]*):([^:]*:.*) /$1_$2 [N]
RewriteRule ^/([^:]*):([^:]*)$ /$1_$2
like image 136
Gumbo Avatar answered Sep 06 '26 15:09

Gumbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!