使用htaccess和mod_rewrite重写URL

时间:2013-08-22 06:58:50

标签: php .htaccess url mod-rewrite

我是htaccess mod_rewrite规则的新手。我想从URL中消除GET变量。我尝试过以下规则:

RewriteEngine On
RewriteCond %{THE_REQUEST} \?[^\ ]+
RewriteRule (.*) /$1? [R=301,L] #remove query string

上述规则取消了查询?id,但它将网址重定向为www.example.com/admin/test.php,没有子目录project和扩展名.php

我想转换

www.example.com/project/admin/test.php?id=1 

www.example.com/project/admin/test

1 个答案:

答案 0 :(得分:0)

浏览 www.example.com/project/admin/test?id=1 www.example.com/project/admin/test.php?id=相同1

RewriteCond %{REQUEST_FILENAME}\.php  -f
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteRule  (.*)  $1.php