unemployment Posted September 7, 2011 Share Posted September 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246618-blog-rewrite-is-almost-perfect/ Share on other sites More sharing options...
trq Posted September 7, 2011 Share Posted September 7, 2011 mod_rewrite has no way of checking to see if the title is correct, that us up to the logic in your blog.php script. Quote Link to comment https://forums.phpfreaks.com/topic/246618-blog-rewrite-is-almost-perfect/#findComment-1266384 Share on other sites More sharing options...
cags Posted September 7, 2011 Share Posted September 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246618-blog-rewrite-is-almost-perfect/#findComment-1266390 Share on other sites More sharing options...
unemployment Posted September 7, 2011 Author Share Posted September 7, 2011 I figured it out guys. Thanks for all the help. You guys are great! Quote Link to comment https://forums.phpfreaks.com/topic/246618-blog-rewrite-is-almost-perfect/#findComment-1266400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.