Jump to content

Blog Rewrite is almost perfect


unemployment

Recommended Posts

I am using this for my blog url rewrite.

 

RewriteRule ^blog/([0-9]+)/.*$ /blog.php?post_id=$1 [L]

 

And that turns blog.php?post_id=3 into blog/3/title-seperated-by-dashes

 

The problem is that even if I just type blog/3/hokdohkd  the link will still work!  I only want the link working if the title is correct too.

Link to comment
Share on other sites

If you are validating the 'title' part of the URL, then you might as well simply switch to using the slug to select from the database rather than the ID and drop the ID from the address altogether. The only reason to leave the id in there would be to allow multiple articles to have the same title, but this wouldn't be the best idea as it will be confusing/misleading for the end user.

 

This is all academic of course, as thorpe says, it's down to the script logic, not mod_rewrite.

 

If you really need to do it then you would (in your script) simply load the blog post, compare the title to that of the blog, and issue a 404 redirect with php.

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.