开发者

Make URL's look good dynamically [duplicate]

This question already has answers here: Closed 11 years ago.

Possible D开发者_如何学JAVAuplicate:

How do I convert a PHP query string into a slash-based URL?

If I have database driven pages with urls like this:

http://www.companyname.com/dynamic_page.php?id=1
http://www.companyname.com/dynamic_page.php?id=2
http://www.companyname.com/dynamic_page.php?id=3
...
http://www.companyname.com/dynamic_page.php?id=4001
http://www.companyname.com/dynamic_page.php?id=4002
http://www.companyname.com/dynamic_page.php?id=4003

Where the id in the url is used to get the correct content from the database, and the user has the ability to add/remove/edit as many pages as s/he wants.

I understand how to manually use mod_rewrite to give the urls a nicer look e.g.

http://www.companyname.com/individual/1
http://www.companyname.com/individual/2
http://www.companyname.com/individual/3
...
http://www.companyname.com/commercial/4001
http://www.companyname.com/commercial/4002
http://www.companyname.com/commercial/4003

But how would I do that dynamically? i.e. allow the user to specify part of the url, in this case the user has selected either "individual" or "commercial", then add the id at the end of the url, without me having to edit the .htaccess file each and everytime a user makes a new page, or edits/deletes a page.


I think that this could be enough:

RewriteRule http://www.companyname.com/(.*)/(\d+) http://www.companyname.com/dynamic_page.php?id=$2

It doesn't matter what is before /4441, it will always lead to dynamic_page.php?id=4441...


Are you manually adding a new line for every ID in the ht access file?

You could accomplish all of this easily with a regular expression. Here's a post that's a bit old but is completely relative to your needs: http://www.webmasterworld.com/forum92/4332.htm


Try this:

RewriteRule http://www.companyname.com/(.*)/(\d+) http://www.companyname.com/index.php?firstvalue=$1&secondvalue=$2


Check out -> Clean Urls

You can try.

RewriteEngine On
RewriteRule ^companyname.com/(.*)/(\d+)$ /$1.php?id=$2
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜