Jump to content

mod rewrite and SEO friendly url's


dakasadaka

Recommended Posts

Hello there,

I'm trying to make my urls to have the post title in the url.

Now I have index.php?id=2

and I want to have title-of-post.html

 

I know that I need to use .httacces and rewrite on, but when I ask in my database id,

can I just ask for title of post and then put it after id=post-of-title.html

 

Or are they smarter and faster ways to make this?

thnx,

Davor Radic

Link to comment
https://forums.phpfreaks.com/topic/192489-mod-rewrite-and-seo-friendly-urls/
Share on other sites

Since the title of an article/page is often not forced to be unique generally speaking URLs will include both. For example...

 

mysite.com/article/10/my-article.html

 

You can then use a rule something like this...

 

RewriteRule ^article/([0-9]+)/[a-zA-Z0-9-]+\.html /article/index.php?id=$1

 

You system will essentially check that the title matches against the characters you allow, but ultimately ignores it since it is the id that is important. If your title is a true 'permalink' that is unique for that article you can simply change that to something like...

 

RewriteRule ^article/([a-zA-Z0-9-]+)\.html /article/index.php?title=$1

 

...and use the title in a similar manner to what your currently using the id.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.