skip to Main Content

I have a site with a lot of url’s like this

www.example.com/this_has_some_meaning.php

Now I learned that for SEO reasons it is better to use

www.example.com/this-has-some-meaning.php

Can i, using htaccess, redirect all the url’s from the old to the new, using some kind of regex?

2

Answers


  1. You can use these 2 rules in your .htaccess:

    RewriteEngine On
    
    # when there is only one underscore then redirect
    RewriteRule ^([^_]*)_+([^_]*)$ /$1-$2 [L,R=301,NE]
    
    # otherwise replace each _ by - recursively
    RewriteRule ^([^_]*)_+(.*)$ $1-$2 [N,DPI]
    
    Login or Signup to reply.
  2. Use given code

     <IfModule mod_rewrite.c>
    RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
    RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
    RewriteRule ^.*$ index.php [L]
    </IfModule>
    

    In the given code developer target 5 sites separated by “|”

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search