Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 731539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:02:18+00:00 2026-05-14T07:02:18+00:00

I’m working on a site, and its CMS used to save new page urls

  • 0

I’m working on a site, and its CMS used to save new page urls using the underscore character as a word seperator.

Despite the fact that Google now treats underscore as a word seperator, the SEO powers that be are demanding the site use dashes instead.

This is very easy to do within the CMS, and I can of course change all existing URLs saved in the MySQL database that serves the CMS.

My problem lies in writing a .htaccess rule that will 301 old style underscore seperated links to the new style hyphenated verstion.

I had success using the answers to this Stack Overflow question on other sites, using:

RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N]
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

However this CMS site uses a lot of existing rules to produce clean URLs, and I can’t get this working in conjunction with the existing rule set.

.htaccess currently looks like this:

Options FollowSymLinks
# RewriteOptions MaxRedirects=50

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mydomain\.co\.uk$ [NC]
RewriteRule (.*) http://www.mydomain.co.uk/$1 [R=301,L]

#trailing slash enforcement
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !#
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1/ [L,R=301]

RewriteRule ^test/([0-9]+)(/)?$ test_htaccess.php?year=$1 [nc]

RewriteRule ^index(/)?$ index.php

RewriteRule ^department/([^/]*)/([^/]*)/([^/]*)(/)?$ ecom/index.php?action=ecom.details&mode=$1&$2=$3 [nc]
RewriteRule ^department/([^/]*)(/)?$                 ecom/index.php?action=ecom.details&mode=$1 [nc]

RewriteRule ^product/([^/]*)/([^/]*)/([^/]*)(/)?$ ecom/index.php?action=ecom.pdetails&mode=$1&$2=$3 [nc]
RewriteRule ^product/([^/]*)(/)?$                 ecom/index.php?action=ecom.pdetails&mode=$1 [nc]
RewriteRule ^content/([^/]*)(/)?$                 ecom/index.php?action=ecom.cdetails&mode=$1 [nc]

RewriteRule ([^/]*)/action/([^/]*)/([^/]*)/([^/]*)/([^/]*)(/)?$ $1/index.php?action=$2&mode=$3&$4=$5 [nc]
RewriteRule ([^/]*)/action/([^/]*)/([^/]*)(/)?$                 $1/index.php?action=$2&mode=$3 [nc]
RewriteRule ([^/]*)/action/([^/]*)(/)?$                         $1/index.php?action=$2 [nc]
RewriteRule ^eaction/([^/]*)/([^/]*)/([^/]*)/([^/]*)(/)?$       ecom/index.php?action=$1&mode=$2&$3=$4 [nc]
RewriteRule ^eaction/([^/]*)/([^/]*)(/)?$                       ecom/index.php?action=$1&mode=$2 [nc]
RewriteRule ^action/([^/]*)/([^/]*)(/)?$                        index.php?action=$1&mode=$2 [nc]
RewriteRule ^sid/([^/]*)(/)?$                                   index.php?sid=$1 [nc]




## Error Handling ##
#RewriteRule ^error/([^/]*)(/)?$ index.php?action=error&mode=$1 [nc]

# ----------------------------------- Content Section ------------------------------ #
#RewriteRule ^([^/]*)(/)?$ index.php?action=cms&mode=$1 [nc]

RewriteRule ^accessibility(/)?$ index.php?action=cms&mode=accessibility
RewriteRule ^terms(/)?$         index.php?action=cms&mode=conditions
RewriteRule ^privacy(/)?$       index.php?action=cms&mode=privacy
RewriteRule ^memberpoints(/)?$  index.php?action=cms&mode=member_points

RewriteRule ^contactus(/)?$ index.php?action=contactus
RewriteRule ^sitemap(/)?$   index.php?action=sitemap

ErrorDocument 404 /index.php?action=error&mode=content

ExpiresDefault "access plus 3 days"

All page URLS are in one of the 3 following formats:

http://www.mydomain.com/department/some_page_address/

http://www.mydomain.com/product/some_page_address/

http://www.mydomain.com/content/some_page_address/

I’m sure I am missing something obvious, but at this level my regex and mod_rewrite skills clearly aren’t up to par.

Any ideas would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:02:19+00:00Added an answer on May 14, 2026 at 7:02 am

    Just take the rule you were using already:

    RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N]
    RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]
    

    …and put it before all other rewrite rules, and everything should work.

    Also, you used RewriteBase / twice. You can omit it the second time, since it’s already defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.