多个查询字符串的htaccess 301重定向规则

问题描述 投票:0回答:1

我只想要多重查询字符串301重定向规则,使其成为SEO友好网址。

内部网址:www.example.com?p=54&p1=ABC XYZ&p2=XXX45767等。

301 Redirect Url:www.example.com/54-ABC-XYZ-XXX45767?p=54&p1=ABC XYZ&p2=XXX45767

因此,重定向网址也必须包含旧的查询参数。

apache .htaccess mod-rewrite redirect url-redirection
1个回答
2
投票

第一步是检查QUERY_STRING中的相关参数。如果找到匹配项,则应进行重定向。

您可以在/.htaccess文件中使用以下内容:

RewriteEngine On

# Check the query string and capture parts
RewriteCond %{QUERY_STRING} ^p=([^&]+)&p1=([^&]+)&p2=([^&]+)$

# If at the root of the domain, redirect
RewriteRule ^$ /%1-%2-%3 [R=302,L]

要使重定向永久化并由浏览器和搜索引擎缓存,请将302更改为301

© www.soinside.com 2019 - 2024. All rights reserved.