Jump to content

mod_rewrite


fohanlon

Recommended Posts

Hi Guys

 

Trying to get my head around a mod_rewrite I am doing.  I found plenty on the web re this question but no definitive answer.  Here is what I have to do.  I have a link to a page called

 

content.php?id=123&name=SOME NAME HERE

 

where id ties back to the 123 for pageid and name is what I want to use for Search Engine Optimisation.

 

So here is what I have so far:

 

RewriteRule ^([^/]*)/([^/]*)$ /content.php?id=$1&name=$2 [L]

 

But what I want to do - only show the name in the url at the top

 

Instead of

 

www.somedomain.com/123/SOME NAME HERE

 

I want

 

www.somedomain.com/SOME NAME HERE

 

but still need to use the id to pull back the page content to be displayed.  Can anyone suggest how to change the rule above?

 

Hope this makes sense and its the right place to post this.

 

Many thanks

 

Fergal.

Link to comment
Share on other sites

The only way of doing it without an id number is by generating unique slugs based on the name. A common way of doing this is simply replacing non-url safe characters with a hypen, checking if it's unique and then incrementing a counter on the end in cases where it isn't, until you find a unique slug. Alternatively, due to the fairly small chance of you getting the same name on the same day, a lot of people use a date structure in their URL, such as /2011/07/26/my-title-here. The basic idea boils down to the same thing though, you need a value unique for that 'article' that you can query the database for. Once you have that you can bang a unique index on it to make searching quicker and Roberts your aunties brother.

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.