Php htaccess重命名为友好url
我有以下网址:Php htaccess重命名为友好url,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我有以下网址: http://example.com/de/cat1/?q=product1 http://example.com/en/cat2/?q=product3 ... 我想把它们重命名如下。 第一个应该是:http://example.com/de/cat1/product1。第二个应该是:http://example.com/en/cat2/product3 换句话说,我只想删除“?q=” My.htaccess未提供正确的结果。 目前情况如下: RewriteEngine On
http://example.com/de/cat1/?q=product1
http://example.com/en/cat2/?q=product3
...
我想把它们重命名如下。
第一个应该是:http://example.com/de/cat1/product1
。第二个应该是:http://example.com/en/cat2/product3
换句话说,我只想删除“?q=”
My.htaccess未提供正确的结果。
目前情况如下:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ ?q=$1 [NC,L]
如果用户输入http://example.com/de/cat1/product1
它将把它变成:http://example.com/de/cat1/?q=/de/cat1/product1
如何修复此问题?这是因为您正在单个组中捕获整个uri,并将其用作目标查询字符串。将重写规则替换为以下内容:
RewriteRule ^(.+)/(.+)$ /$1?q=$2 [L]
这很有效。非常感谢。是否可以在地址字段中保留SEO友好的URL,而不是将其更改为真实的URL?我想保留
http://example.com/de/cat1/product1
在地址字段中。@user9是的,这是可能的。您需要将旧url重定向到新url。你可以用重写规则,我不知道怎么做。如何修改我的htaccess?