Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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 在Apache中重写带有两个参数的查询字符串_Php_Apache_.htaccess_Query String - Fatal编程技术网

Php 在Apache中重写带有两个参数的查询字符串

Php 在Apache中重写带有两个参数的查询字符串,php,apache,.htaccess,query-string,Php,Apache,.htaccess,Query String,我通常不使用Apache,但在这里我不得不这么做。我在重写一个URL时遇到了问题,该URL在查询字符串上使用了两个参数并重写了它 原始URL是:products.php?artist={artist\u slug}&product={product\u slug},我想将其重写为/artists/{artist\u slug}/products/{product\u slug} 重写RewriteRule^artists/([a-zA-Z0-9-]*)//artist.php?artist=$1

我通常不使用Apache,但在这里我不得不这么做。我在重写一个URL时遇到了问题,该URL在查询字符串上使用了两个参数并重写了它

原始URL是:
products.php?artist={artist\u slug}&product={product\u slug}
,我想将其重写为
/artists/{artist\u slug}/products/{product\u slug}

重写
RewriteRule^artists/([a-zA-Z0-9-]*)//artist.php?artist=$1
可以很好地工作,但只要我从这个扩展到

RewriteRule^artists/([a-zA-Z0-9-]*)/products/([a-zA-Z0-9-]*)///products.php?artist=$1&product=$2


它扔给我一个404。有人知道我做错了什么吗?提前感谢您的帮助。

尝试使用以下规则:

RewriteEngine On
RewriteCond %{QUERY_STRING} artist=(.*)&product=(.*)$ [NC]
RewriteRule ^ http://%{HTTP_HOST}/artists/%1/products/%2? [R=301,L]
这将获取两个查询字符串,然后将它们重写为以下URL
http://example.com/artists/{artist_slug}/products/{product_slug}
。您将看到我在重写的末尾添加了一个
。也就是说,阻止
query\u字符串
出现在URL的末尾

在测试此项之前,请确保清除缓存