Jump to content

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.

 

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.