开发者

PHP id in .htaccess

开发者 https://www.devze.com 2023-02-21 18:59 出处:网络
I Have a 开发者_开发技巧.htaccess file for a blog script which currently generates a number for a blog post based on it\'s ID in the MySQL database. Is there any way I can change this so that it uses

I Have a 开发者_开发技巧.htaccess file for a blog script which currently generates a number for a blog post based on it's ID in the MySQL database. Is there any way I can change this so that it uses something like $subject as the URL from my PHP file? I have pasted my current .htaccess code below.

RewriteEngine On RewriteRule ^blog-([0-9]+).html$ index.php?act=blog&id=$1

I hope people can understand what I am trying to describe. Thanks in advance.

Regards, Callum Whyte


Using just the subject is probably a bad idea, if you ever change the title, all links to your page (from google, or elswhere) will be broken. I would include both the subject and the idea, that way you'll always be able to match an URL to a blog post:

RewriteEngine On RewriteRule ^blog-[^-]+-([0-9]+).html$ index.php?act=blog&id=$1

This should match everything except a - between blog and the id. Now you should be able to call, e.g., *yousite/blog-some_title_or_other-494.html* and it will call index.php?act=blog&id=494. This new rule shouldn't break any of your old backlinks either. If it does, let me know and I'll fix it.

0

精彩评论

暂无评论...
验证码 换一张
取 消