Skip to content

Instantly share code, notes, and snippets.

@hmngwy
Last active August 29, 2015 14:05
Show Gist options
  • Save hmngwy/e1bad35ddcc6431d07d3 to your computer and use it in GitHub Desktop.
Save hmngwy/e1bad35ddcc6431d07d3 to your computer and use it in GitHub Desktop.
mod_rewrite directives for underscore-separated-paths into dashes, in .htaccess, without any site file changes
RewriteEngine On
RewriteCond %{QUERY_STRING} !(.*)r=1(.*)
RewriteCond %{REQUEST_URI} ^(.*)html$
RewriteCond %{REQUEST_URI} ^(.*)_(.*)$
RewriteRule (.*)_(.*) http://www.example.com/$1-$2 [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)-(.*)$
RewriteRule (.*)-(.*) /$1_$2?r=1 [L]
RewriteCond %{QUERY_STRING} !(.*)r=1(.*)
RewriteCond %{REQUEST_URI} ^(.*)html$
RewriteCond %{REQUEST_URI} ^(.*)_(.*)_(.*)$
RewriteRule (.*)_(.*)_(.*) http://www.example.com/$1-$2-$3 [R=301]
RewriteCond %{REQUEST_URI} ^(.*)-(.*)-(.*)$
RewriteRule (.*)-(.*)-(.*) /$1-$2-$3 [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment