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.

Fixing Case Sensitive, Urgent Help Required

Discussion in 'PHP' started by zehrila, Jun 6, 2011.

  1. #1
    Okay, by default my urls structure is in mixed case, e.g domain.com/Green-Blue-Widgets.html and Google for some reasons is indexing two versions of my urls domain.com/Green-Blue-Widgets.html and domain.com/green-blue-widgets.html . Now i want to 301 redirect all urls to lowercase, but my internal navigation is all mixed case e.g the category page domain.com/Green has all the products listed in the page with mixed case.

    I know its bad programming, but i will really appreciate if any one can look into the matter for me and usggest a solution.
     
    zehrila, Jun 6, 2011 IP
  2. SiJz

    SiJz Peon

    Messages:
    51
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Are the urls in a fixed format? as shown above, where the first letter only uppercase or more complext than that?
    Also how complex is the url path? as above or with folders too?

    The task is mostly using .htaccess rather than php...

    I'll try a few htaccess methods and post back soon

    Si
     
    SiJz, Jun 6, 2011 IP
  3. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #3
    The simplest solution is to use the rel="canonical" tag on your webpages. All of the major search engines support this tag and will eventually canonicalize your URLs in their index. Of course, you should also work to homogenize all of your internal links to match the canonical URLs you use. See Google's Recommendation for details. Good luck!
     
    rainborick, Jun 6, 2011 IP
  4. SiJz

    SiJz Peon

    Messages:
    51
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    I've looked into it.. there are a few ways, htaccess only is really ugly and can slow things down a lot.

    So I came up with this...

    yout .htaccess needs to be changed to add this:
    
    RewriteEngine on
    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule (.*) http://yourdomain.com/urlw.php?u=$1 [R=301,L]
    
    Code (markup):
    this basically detects if upper case characters are present, if so, it then redirects to the php script
    so if you entered
    http://yourdomain.com/Apple-Pie.php
    Code (markup):
    it would redirect to
    http://yourdomain.com/urlw.php?u=Apple-Pie.php
    Code (markup):
    urlw.php is as follows:
    
    <?php
    $URL = $_REQUEST['u'];		// incoming url
    $URL = strtolower($URL);	// force lower case
    $URL = strip_tags($URL);
    header("Location: ".$URL, TRUE, 301);
    ?>
    
    Code (markup):
    this gets the filename, forces it to lower case, does a bit of safety checking of the string, then performs a 301 redirect

    Hope this helps?

    Si
     
    SiJz, Jun 6, 2011 IP