[英]htaccess renaming into friendly url
I have the following URLs: 我有以下网址:
http://example.com/de/cat1/?q=product1
http://example.com/en/cat2/?q=product3
...
I would like to rename them as follows. 我想将它们重命名如下。 The first one should become: http://example.com/de/cat1/product1
. 第一个应该变成: http://example.com/de/cat1/product1
: http://example.com/de/cat1/product1
。 The second one should become: http://example.com/en/cat2/product3
第二个应该变成: http://example.com/en/cat2/product3
: http://example.com/en/cat2/product3
In other words I just want to remove "?q=". 换句话说,我只想删除“?q =“。
My .htaccess does not provide the correct result. 我的.htaccess没有提供正确的结果。 It looks currently as follows: 当前看起来如下:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ ?q=$1 [NC,L]
If the users enters http://example.com/de/cat1/product1
it would turn it into: http://example.com/de/cat1/?q=/de/cat1/product1
. 如果用户输入http://example.com/de/cat1/product1
,它将变成: http://example.com/de/cat1/?q=/de/cat1/product1
: http://example.com/de/cat1/?q=/de/cat1/product1
。
How can I fix that? 我该如何解决?
This is because you are capturing the entire uri in a single group and using it as destination querystring. 这是因为您要在单个组中捕获整个uri,并将其用作目标查询字符串。 Replace your RewriteRule with the following : 将RewriteRule替换为以下内容:
RewriteRule ^(.+)/(.+)$ /$1?q=$2 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.