Reputation: 329
I have the a rewrite rule where I am trying to remove any dots and parentheses from the URL and I managed to get get to the point where I can do one or the other but just can't seem to combine both. How would I write the rule so that if any url has a dot or parentheses, they get removed? Thanks.
RewriteEngine On
RewriteCond %{REQUEST_URI} [\(\)\.]+
RewriteRule ^(.*)[\(]+([^\)]*)[\)]+(.*)$ /$1$2$3 [L,R=301]
Upvotes: 0
Views: 662
Reputation: 143906
Try:
RewriteRule ^(.*)[().](.*)$ /$1$2 [E=DOT:Y,DPI]
RewriteCond %{ENV:DOT} Y
RewriteRule ^([^().]+)$ /$1 [L,R=301]
This uses an environment variable as a way to know when to redirect. Any number of parentheses and dots will get removed and when they're all done, the URL gets redirected.
Upvotes: 1