htaccess的查询字符串重定向不工作

问题描述:

我试图http://example.com/for-sale/?property=1234重定向到http://example.com/for-sale/property-name/在.htaccess中,使用的RewriteCond重写规则和。这是我到目前为止:htaccess的查询字符串重定向不工作

RewriteCond %{QUERY_STRING} ^(property=1234) 
RewriteRule ^$ /for-sale/property-name/? [R=301,L] 

这是行不通的。我可以将?property = 1234重定向到for-sale/property-name /,但是如何使它在/ for-sale /在未重定向的URL中工作?我已经尝试了RewriteRule中的各种待售组合,但没有成功。 谢谢。 我所有的链接现在都被打破了,所以我会非常感谢一些建议。谢谢。

+0

不,它是由WordPress生成的,来自'register_post_type'中的'rewrite'参数。我发现了问题并修复了它,请参阅下面的答案。 – ardmark

这是一个WordPress的网站,所以第一个错误是WordPress的做它重写后做了重写。第二个错误是在RewriteRule中。这里是工作代码:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} property=1234$ 
RewriteRule ^for-sale/?$ /for-sale/property-name/? [R=301,L] 

... my other rewrites 

</IfModule> 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

这个工程。希望它能帮助别人。