1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help changing URL's on my sites

Discussion in 'Apache' started by PHP Bear, Mar 21, 2014.

  1. #1
    I have several websites with URL's in the following format:

    GW/World/Isthmus_of_Panama
    GS/World/Isthmus_of_Panama
    GZ/Life/Canis_lupus

    First Goal

    I want to change all my URL's to lower case and replace the underscores with dashes:

    gw/world/isthmus-of-panama
    gs/world/isthmus-of-panama
    gz/life/canis-lupus

    Second Goal

    I don't want to lose visitors that continue linking to the old URL's. So if someone types in GZ/Life/Canis_lupus, rather than display a 404 error page, I would like them to be forwarded to gz/life/canis-lupus.

    In fact, I'd like all links that have the appropriate characters to work, whether separate words are separated by an underscore, dash or space...

    gz/world/isthmus-of-panama
    gz/World/Isthmus_of_Panama
    gz/World/iTHMUS of_panama

    Third Goal

    I don't know how this will affect my statistics, but, if possible, I would like to avoid this:

    gz/world/new-york - 22 hits
    gz/world/new_york 16 hits
    gz/world/New York 3 hits

    Instead, I'd like to see gz/world/new-york 39 hits.

    * * * * *

    So imagine someone types in MySite/world/new-yorx. That would fetch a 404 error page.

    If they type in MySite/world/New York, the url will default to MySite/world/new-york. (Wikipedia has a similar function.)

    At first, I thought I would have to do TWO things: 1) Modify my PHP database query so that it accepts URL variations (upper vs lower case, _, -, space), then 2) modify .htaccess so that any of these accepted URL's default to the preferred URL. But after doing more research, I THINK I can do all of this with .htaccess. Am I right?

    If so, can anyone advise me how to modify my .htaccess files? Below is a portion of an .htaccess file from one of my sites. It may have bugs in it, though it works for my current site.

    Sorry for the LONG post, and thanks for any tips. ;)

    RewriteEngine On
    RewriteRule ^test\.htm$ test.php [L]
    Options -MultiViews
    
    DirectoryIndex index.php index.html yadda-yadda.pl
    
    php_flag magic_quotes_gpc Off
    
    RewriteRule ^/?world/([a-zA-Z0-9()_/-]+)$ world/index.php?area=$1 [L]
    RewriteRule ^/?reference/([a-zA-Z0-9_/-]+)$ reference/index.php?ref=$1 [L]
    Code (markup):
     
    PHP Bear, Mar 21, 2014 IP