Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 将cond%{QUERY_STRING}重写为特定URL_.htaccess_Redirect - Fatal编程技术网

.htaccess 将cond%{QUERY_STRING}重写为特定URL

.htaccess 将cond%{QUERY_STRING}重写为特定URL,.htaccess,redirect,.htaccess,Redirect,我将一个旧站点迁移到WordPress,目前正在为.aspx页面设置各种301重定向。旧站点使用查询字符串来显示某些页面,所以我想将这些页面映射到新的SEO URL 基本“静态”页面的当前代码运行良好: Redirect 301 /about-us.aspx http:// example.com/about-us/ Redirect 301 /get-in-touch.aspx http:// example.com/contact/ Redirect 301 /services.aspx h

我将一个旧站点迁移到WordPress,目前正在为.aspx页面设置各种301重定向。旧站点使用查询字符串来显示某些页面,所以我想将这些页面映射到新的SEO URL

基本“静态”页面的当前代码运行良好:

Redirect 301 /about-us.aspx http:// example.com/about-us/
Redirect 301 /get-in-touch.aspx http:// example.com/contact/
Redirect 301 /services.aspx http:// example.com/services/
问题在于以下查询字符串:

Redirect 301 /services.aspx?type=14 http:// example.com/services/service-a/
Redirect 301 /services.aspx?type=17 http:// example.com/services/service-b/
我已经读到,为了正确地重定向这些查询字符串,我必须使用RewriteCond。我在simonecarletti的博客上读到以下内容:将查询字符串传递到URI的末尾

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page\.php$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ http://mydomain.site/page/%1.pdf [R=302,L]
这对我来说并不实用,因为我在它们的URL中有以服务命名的关键字。身份证号码毫无意义

在阅读了这里的几个问题[11544773,2562139817919953]之后,我一直在尝试各种各样的建议,但没有任何运气

如果我访问:

/services.aspx?type=14
我被重定向到:

/services/?type=14
如何重定向到新的URI,例如

/services/service-a/
下面是我正在玩的乱七八糟的代码:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^type=14$
#RewriteCond %{REQUEST_URI}  ^/services\.aspx$
RewriteRule ^ http://example.com/service-a/? [R=301,L]

您拥有的代码应该可以工作,您只需要检查URI中的服务:

RewriteCond %{QUERY_STRING} ^type=14$
RewriteRule ^services\.aspx$ http://example.com/services/service-a/? [R=301,L]

谢谢你的意见。我厌倦了你的修正案,起初什么也没发生。然后我明白了。这些规则都需要在WordPress重写规则之前调用。如期工作