Redirect URLs with underscores to URLs with dashes (hyphens)

| No Comments


After all the re-publishing and researching I did yesterday, I realized that the filenames on my old blog site used underscores - not dashes - and, because of that, some links were broken on this new blog! Ack! (I knew I wanted to use dashes so I thought I had already been using dashes on the old blog!) I was by then too tired to try to fix it.

Today, however, I was ready to tackle this new problem! A Google search for "htaccess underscores dashes" revealed just what I needed! Using .htaccess Voodoo For Underscore and Dash Woes provides the solution with the exact lines to copy and paste into the .htaccess file. Changes I made:

  • There were 2 extra spaces that caused 500 errors until I removed them from the last and next-to-last lines just before \.html$
  • Changed "RewriteBase /" to the subdirectory for this blog, i.e., "RewriteBase /blog/"
  • Since I use .php extensions, I changed .html to .php
  • Added lines for $7, $8, $9 ,$10, and $11 because full titles use more than 6 words in some cases

Works like a charm!

[Update October 28, 2007] It seems that the wildcards go to only $9. So I added this line (it's one line, not three!) above the $9 line - it catches the first nine wildcard variables then the lines below this one catch the rest.

RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)
_([^_]*)_([^_]*)_(.*)\.php$
http://www.tamemymind.com/$1-$2-$3-$4-$5-$6-$7-$8-$9.php

Leave a comment

Sketch of Cheryl

About Cheryl

Enjoys crocheting, gardening, cats, NASCAR (especially Tony Stewart and Kyle Busch!), reading, photography, snorkeling in Kailua-Kona with sea turtles, Sizzler's Mega Bacon Cheeseburgers, hot and iced decaf coffee, dark chocolate, color (yarn, fabric), playing around with web technologies - not necessarily in that order! Still very much a beginner with quilting, knitting, and sewing. Donates crocheted lap blankets.

List maker, detail-oriented, organized, leans heavily toward perfectionism. ISTJ. Libra.

January 2017

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Disclaimer: This is a personal website - my place of self expression. The views expressed are mine alone and do not necessarily reflect the views of my employer or any other organization I am a member of or affiliated with.
Creative Commons License
This blog is licensed under a Creative Commons License.
Powered by Movable Type 5.2.2

About this Entry

This page contains a single entry by Cheryl published on October 22, 2007 7:05 AM.

More MT 4 configuration notes was the previous entry in this blog.

Use sed to change string1 to string2 in same file is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Cat playing with strand of yarn.

Categories





HERE1 HERE2