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
https://forums.phpfreaks.com/topic/246618-blog-rewrite-is-almost-perfect/
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.

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.