PHP URL Rewrite

前端 未结 1 994
无人及你
无人及你 2020-12-11 05:58

i have a url like this.

http://www.somesite.com/community.php?id=4

for id number 4 would equal Washington for id number 5 would equal Den

相关标签:
1条回答
  • 2020-12-11 06:48

    Have a look at mod_rewrite: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    You can, for example, do it like this:

    RewriteEngine on
    RewriteRule washington community.php?id=4 [L,QSA]
    RewriteRule denver community.php?id=5 [L,QSA]
    

    This would, of course, lead to a LOT of rewrite rules if you have much cities. So, a IMHO smarter way would be to rewrite the URI slug to community.php and lookup the ID from some sort of database:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCOnd %{REQUEST_FILENAME} !-d
    RewriteRule /?([a-z-]+) community.php?city=$1 [L,QSA]
    

    HTH

    0 讨论(0)
提交回复
热议问题