Mod_Rewrite动态页面和重定向

时间:2014-01-03 16:03:49

标签: php apache mod-rewrite url-rewriting

我正在创建一个带有url的动态页面,例如:

http://www.mydomain.co.uk/stocklist/item.php?id=int&name=string

有没有办法可以将网址重写与重定向相结合,将所有动态链接指向:

http://www.mydomain.co.uk/stocklist/id/name

1 个答案:

答案 0 :(得分:2)

RewriteEngine On
# add this following cond if the Rewrite rule rewrites css, js etc. files
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^stocklist/([0-9]+)/(.*)$ stocklist/item.php?id=$1&name=$2 [L,NC]