将url查询字符串重写为path

时间:2016-07-14 12:34:14

标签: apache .htaccess mod-rewrite url-rewriting query-string

我有这样的网址:

/用户/注册/?user_group_id =买家

我会把它转换成:

/用户/注册/买家/

我尝试了很多方法,但是他们没有工作,mod重写是为了其他指示而设计的。

在我的htaccess中:

RewriteEngine On
RewriteBase /

#without www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#with www
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)
RewriteRule ^(.*) http://www.%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

RewriteRule ^user/registration/([^/]*)$ /user/registration/?user_group_id=$1 [L]

<Files *.ini>
    order deny,allow
    deny from all
</Files>

谢谢

1 个答案:

答案 0 :(得分:0)

使用此:

RewriteEngine On
RewriteRule ^user/registration/([^/]*)$ /user/registration/?user_group_id=$1 [L]

它将为您提供路径:/user/registration/buyers/