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.

How to correct the URL using php

Discussion in 'PHP' started by Flightsandfly1, May 28, 2012.

  1. #1
    Hello,
    i am working on a flights website, but on one page i am getting error of 404. This error is comming due to the ' / ' this symbol which appears at the end of URL. like : http://www.flightsandfly.co.uk/cheap_flights_to_abuja.htm/ . So if we remove this last / symbol then we get actual result but there is one main problem that this (http://www.flightsandfly.co.uk/cheap_flights_to_abuja.htm/) link is used in many places while performing SEO. so what i want is to remove this / from the end. and the links are generating randomly from database and this is done by REWRITE ENGINE. just like
    cheap_flights_to_(.*).htm. so what ever city will be selected from database then automatically page appear of that city.

    Kindly help me that how can i remove this / from the end. is there any method to check the URL ?



    Thanks
     
    Flightsandfly1, May 28, 2012 IP
  2. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #2
    
    <?php
    $url = "http://www.flightsandfly.co.uk/cheap_flights_to_abuja.htm/";
    if (substr($url, -1) == '/')
    {
    	$url = substr($url, 0, -1);
    }
    echo $url;
    ?>
    
    PHP:
     
    kbduvall, May 28, 2012 IP
  3. Flightsandfly1

    Flightsandfly1 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    where i have to place this code "either in header or in body"?
     
    Flightsandfly1, May 29, 2012 IP
  4. burlesk

    burlesk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You put in the code where your link is created. Instead of kbduvall's example, you could also use rtrim($url, '/').

    For proper SEO you can make the links with "/" redirect to the correct ones using a .htaccess rule. Something like:

    RewriteRule cheap_flights_to_(.*).htm./ cheap_flights_to_(.*).htm. [R=301]

    I haven't tested it, but the idea is to redirect the use to the page without the "/".
     
    burlesk, May 29, 2012 IP
  5. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #5
    Yeah, rtrim would probably be a better solution than substr. I'm also a fan of mod_rewrite for things like this but if I were going to go that route, I'd also strip the ".htm" portion from the displayed URL in the rewrite rule. That's just my preference though.
     
    kbduvall, May 29, 2012 IP
  6. burlesk

    burlesk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Some people say, that having a .html suffix is better for SEO. I, personally, doubt it.
     
    burlesk, May 30, 2012 IP
  7. sufalamtech

    sufalamtech Peon

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can redirect the old url which is not working to the new one url. Just put refresh tag in coding.
     
    sufalamtech, May 31, 2012 IP