为什么Mod重写URL仍然重定向url?

时间:2017-10-31 14:44:37

标签: php apache .htaccess mod-rewrite

这是我的mod重写代码(.htaccess)

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^test/(.*)$ /test.php?id_val=$1 [L]
DirectoryIndex index.php

当我尝试访问https://www.example.com/test/12345

它将重定向到https://www.example.com/test.php?id_val=12345

我该怎么办?

1 个答案:

答案 0 :(得分:0)

更改规则的顺序并稍微修改一下代码:

DirectoryIndex index.php
RewriteEngine on

RewriteRule ^test/(.+)$ /test.php?id_val=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]