Jump to content

Confusion with mod rewrite?


merylvingien

Recommended Posts

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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.