merylvingien Posted October 16, 2009 Share Posted October 16, 2009 Hi guys and gals, i have browsed a few sites and tried a few different suggestions to do with mod rewrite but i cant seem to make any progress! I have several hundred urls that look like these: http://www.mysite.com/postcode.php?postcode=sp11&postcodesearch=Submit http://www.mysite.com/postcode.php?postcode=rg21&postcodesearch=Submit Basicly i would just like to clean these urls up to make them a bit more search engine friendly, something like: http://www.mysite.com/postcode/sp11 http://www.mysite.com/postcode/rg21 would be nice. Can anyone spare me a moment to help out here? Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/ Share on other sites More sharing options...
gizmola Posted October 16, 2009 Share Posted October 16, 2009 What's your mod rewrite rules look like right now? Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938205 Share on other sites More sharing options...
merylvingien Posted October 16, 2009 Author Share Posted October 16, 2009 Well i tried this that i found on google Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteRule ^postcode/([0-9]+)/$ postcode.php?=postcode$1&postcodesearch=Submit [L] Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938207 Share on other sites More sharing options...
cags Posted October 16, 2009 Share Posted October 16, 2009 Your current code only matches 0-9 and there must be a trailing slash. Your examples seem to include letters also, so you would want something more like... RewriteRule ^postcode/([a-z0-9]+)/?$ postcode.php?=postcode$1&postcodesearch=Submit [L] Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938223 Share on other sites More sharing options...
merylvingien Posted October 16, 2009 Author Share Posted October 16, 2009 Thanks for the replies fellas, still no joy! Before anyone asks, i have tried the page_one - page_two experiment to see if mod rewrite is enabled and that works fine. Hmmmm? Scratches head! Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938230 Share on other sites More sharing options...
gizmola Posted October 16, 2009 Share Posted October 16, 2009 Your RewriteRule doesn't match what you're trying to do for several reasons. You need to do some reading about regular expression syntax, which is what the rewrite rules require. This is closer, but I can't make any guarantees: RewriteRule ^postcode/([^/\.]+)/?$ postcode.php?postcode=$1&postcodesearch=Submit [L] Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938250 Share on other sites More sharing options...
merylvingien Posted October 16, 2009 Author Share Posted October 16, 2009 Yea i noticed the = was in the wrong place, all sorted now though! My understanding was different from what the actual result is! I thought that mod_rewrite actually changed the url, for instance http://www.mysite.com/postcode.phpblablabla ceased to exist and now became http://www.mysite.com/postcode/bla But i now see that it doesnt work that way at all. http://www.mysite.com/postcode.phpblablabla still exists and is active, can still be viewed by typing that url into the browser, but if i type http://www.mysite.com/postcode/bla into the broswer i get the same page! Although i did have to duplicate my css sheets and images into a folder named postcode! But overall a result! Yahoo hasnt picked up any of these pages so far and they have been up for well over a couple of months now! Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938255 Share on other sites More sharing options...
gizmola Posted October 16, 2009 Share Posted October 16, 2009 Yes -- because if they weren't there, then your code wouldn't work anymore. As you stated, it's all about making them friendly for search engines, so you want those to be published. The other thing you want to do once you have this working, is make sure that your internal url's specify the pretty url format you now have working. Needless to say, search engines spider your site and derive url's from your own pages, so you don't want them to be showing the old/internal format anymore. Quote Link to comment https://forums.phpfreaks.com/topic/177942-confusion-with-mod-rewrite/#findComment-938345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.