Php 在Apache中重写带有两个参数的查询字符串
我通常不使用Apache,但在这里我不得不这么做。我在重写一个URL时遇到了问题,该URL在查询字符串上使用了两个参数并重写了它 原始URL是: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
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]
这将获取两个查询字符串,然后将它们重写为以下URLhttp://example.com/artists/{artist_slug}/products/{product_slug}
。您将看到我在重写的末尾添加了一个?
。也就是说,阻止query\u字符串
出现在URL的末尾
在测试此项之前,请确保清除缓存