Trey Trey - 1 year ago 74
Apache Configuration Question

Apache Replace two connected characters to one in url

With apache in the htaccess I would like to replace all periods in the url only when there is an underscore after it.

I want
to redirect to

Can someone tell me how to do this?
Here is what I have, not sure where to go from here or how to properly debug. Thanks.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)\._(.*)$
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301]

Answer Source

You can use this rule:

# execute when there are multiple occurrences of ._
RewriteCond %{REQUEST_URI} ^/(.*)\.(_.*\._.*)$
RewriteRule ^ /%1%2 [L]

# execute when there is only one occurrence of ._
RewriteCond %{REQUEST_URI} ^/(.*)\.(_.*)$
RewriteRule ^ /%1%2 [L,NE,R=301]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download