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
<?php $url = "http://www.flightsandfly.co.uk/cheap_flights_to_abuja.htm/"; if (substr($url, -1) == '/') { $url = substr($url, 0, -1); } echo $url; ?> PHP:
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 "/".
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.
You can redirect the old url which is not working to the new one url. Just put refresh tag in coding.