htaccess使用查询字符串

时间:2016-02-24 11:07:05

标签: php .htaccess redirect

我收到此网址https://domain.com/user.php/123456。 我想使用htaccess将此网址重定向到https://domain.com/user/123456

我的htaccess代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/(.+)$ $1.php/$2 [L]

我通过爆炸(“/”)并根据查询字符串id获取用户信息来内部处理此URL。

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:1)

请尝试以下规则。

 RewriteEngine on
#1--redirect from "user.php/foo" to "user/foo"
RewriteCond %{THE_REQUEST} /user\.php/([^\s]+) [NC]
RewriteRule ^ /user/%1 [L,R]
#2--rewrite "user/foo" to "user.php/foo"
RewriteRule ^user/(.+)$ /user.php/$1 [NC,L]