Reputation: 2496
I could not find the exactly the same question on SO. I hope someone can help me out with this.
Say, user entered http://www.example.com/abc#!def
, and what I want to do is remove all symbols in the ${REQUEST_URI}
portion, then do a redirect to http://www.example.com/abcdef
. The problem is that these symbols can occur anywhere in the string, e.g. #ab!cdeg
and abcdef#!
should both redirect to abcdef
.
If I'm correct, there is no string replace function for mod_rewrite, so this seems impossible to do, but am I correct?
Upvotes: 3
Views: 2110
Reputation: 74028
You can capture specific parts of an URL with regular expressions in a RewriteCond
or RewriteRule
, but not remove arbitrary characters.
Furthermore, you will never see the hash character '#' and everything after it in a URL, because it is used by the client to navigate to a specific part of the document.
Update using the next flag:
RewriteRule (.*)[^a-zA-Z](.*) $1$2 [N]
This rule removes all characters, which are not ^
alphabetic.
Upvotes: 2