Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess重命名为友好url_Php_.htaccess_Url Rewriting - Fatal编程技术网

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?