.htaccess underscores
September 24, 2004 12:15 PM
.htaccess question. I want to turn all the underscores in a url into dashes. More inside..
I'm starting to use the new dynamic page option MT 3.1 offers, and using the change as an opportunity to redesign and 'clean house'. I've read about how using underscores for dirification doesn't work as well with search engines as using dashes. I've got my pages in my fresh build using dashes, but I want to redirect all of the inbound links, search engine requests, etc. to the new version.
But I don't know how. Currently, my archive structure looks like this:
/tester/archives/2004/09/10/mt_31_installation
But, I want it to look like this:
/tester/archives/2004/09/10/mt-31-installation
Any ideas about the code involved? The structure is pretty rigid:
/YYYY/MM/DD/dirified-title-with-multiple-words
I'm starting to use the new dynamic page option MT 3.1 offers, and using the change as an opportunity to redesign and 'clean house'. I've read about how using underscores for dirification doesn't work as well with search engines as using dashes. I've got my pages in my fresh build using dashes, but I want to redirect all of the inbound links, search engine requests, etc. to the new version.
But I don't know how. Currently, my archive structure looks like this:
/tester/archives/2004/09/10/mt_31_installation
But, I want it to look like this:
/tester/archives/2004/09/10/mt-31-installation
Any ideas about the code involved? The structure is pretty rigid:
/YYYY/MM/DD/dirified-title-with-multiple-words
You'll have to extend it for more than one dash, however.
rewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ $1-$2-$3-$4-$5.html [E=unscors:Yes]
rewriteRule ^([^_]*)_([^_]*)_(.*)\.html$ $1-$2-$3.html$ [E=unscors:Yes]
rewriteRule ^([^_]*)_(.*)\.html$ $1-$2.html [E=unscors:Yes]
#
rewriteCond %{ENV:unscors} ^Yes$
rewriteRule ^(.*)\.html$ http://www.example.com/$1.html [R=301,L]
posted by Civil_Disobedient at 1:38 PM on September 24, 2004
rewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ $1-$2-$3-$4-$5.html [E=unscors:Yes]
rewriteRule ^([^_]*)_([^_]*)_(.*)\.html$ $1-$2-$3.html$ [E=unscors:Yes]
rewriteRule ^([^_]*)_(.*)\.html$ $1-$2.html [E=unscors:Yes]
#
rewriteCond %{ENV:unscors} ^Yes$
rewriteRule ^(.*)\.html$ http://www.example.com/$1.html [R=301,L]
posted by Civil_Disobedient at 1:38 PM on September 24, 2004
Argh, one more time... (make sure your browser is at full width so you see where the line breaks are.)
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3-$4-$5.html [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3-$4.html [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3.html [R=301,L]
RewriteRule ^([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2.html [R=301,L]
posted by Civil_Disobedient at 1:41 PM on September 24, 2004
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3-$4-$5.html [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3-$4.html [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2-$3.html [R=301,L]
RewriteRule ^([^_]*)_(.*)\.html$ http://www.mysiteurl.com/$1-$2.html [R=301,L]
posted by Civil_Disobedient at 1:41 PM on September 24, 2004
It is indeed. Regular expressions are your fiend.
posted by Civil_Disobedient at 1:01 AM on September 25, 2004
posted by Civil_Disobedient at 1:01 AM on September 25, 2004
This thread is closed to new comments.
RewriteEngine On
RewriteRule ^([^_]*)_(.*)$ $1-$2 [R=301,L]
posted by Civil_Disobedient at 1:33 PM on September 24, 2004