如何重写.htaccess中的URL,这里有什么错误

时间:2015-09-06 17:36:06

标签: php apache .htaccess mod-rewrite url-rewriting

认为用户输入

localhost/app/public/anything/anything/index/php/id/5

然后id喜欢将其更改为

localhost/app/public/index.php?id=5

我写的表达是

RewriteRule ^index/php/id/([0-9]+)$ http://localhost/saecms/public/index.php?id=$1 [L]

但它不起作用,这里有什么不对?谢谢

1 个答案:

答案 0 :(得分:1)

您可以在/app/public/.htaccess文件中使用此规则:

RewriteEngine On
RewriteBase /app/public/

RewriteRule (?:^|/)index.php/id/(\d+)/?$ index.php?id=$1 [L,QSA,NC]