开发者

Using PHP how do I make a rewrite rule? [duplicate]

开发者 https://www.devze.com 2022-12-09 03:34 出处:网络
This question already has answers here: How do I make a rewrite rule in php? (3 answers) Closed 7 ye开发者_C百科ars ago.
This question already has answers here: How do I make a rewrite rule in php? (3 answers) Closed 7 ye开发者_C百科ars ago.

Using mod rewrite for the first time. Please help me with these rules

I'd like my urls rewritten for pages as follows:

list.php?city=dallas >>> list/city/dallas

profile.php?id=12 >>> profile/zaknuman (username retrieved from db)

story.php?id=33 >>> story/there-are-no-ants-in-texas (story title retrieved from db)


RewriteRule list/city/([a-zA-Z])$ list.php?city=$1

which should match every character in the range a-z and A-Z after the final slash.

The other two I believe you'll need to embed the slug ('zaknuman' and 'there-are-no-ants-in-texas') in the database and then you'll be able to retrieve that slug from the database and get your ID that way, vis:

RewriteRule profile/(.*)$ profile.php?slug=$1

RewriteRule story/(.*)$ story.php?slug=$1

These last 2 match every character after the final slash.

EDIT: Don't forget to make sure you have "RewriteEngine On" in your .htaccess file or Apache configuration!

0

精彩评论

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