将带有参数的URL重定向到另一个参数URL

时间:2018-09-11 12:33:33

标签: wordpress .htaccess parameters url-rewriting


自昨晚以来,我一直在寻找我的重定向解决方案。

我正在将wordpress与search&filter插件一起使用。但是它将错误的分类标签用于结果。我无法覆盖分类法...
这是我为我的问题所致。我想将带有参数的错误网址重定向到正确的网址。

我的旧网址是:/ category / familien?ortregion = aichach
我的新网址应为:/ category / familien?ort = aichach

这是我的.htaccess方法,但是我的问题是重写特定参数。

RewriteCond %{QUERY_STRING} ^ortregion=aichach$ [NC]
RewriteRule ^/category/familien?ort=aichach$ %{REQUEST_URI}? [NC,L,R=301]

希望您能帮助我。

3 个答案:

答案 0 :(得分:0)

请尝试这个

RewriteCond %{QUERY_STRING} (^|&)(ortregion|ort)=[^&]+ [NC]
RewriteRule ^/category/familien/? [NC,L,R=302]

答案 1 :(得分:0)

我认为它可能对您有用。您无需更改.htaccess规则,而需要使用WordPress重写API添加新的重写规则。

/ *自定义挂钩-分类重写* /

function your_plugin_rewrite_rule(){

add_rewrite_rule("^taxonomy/([^/]+)/([^/]+)",'index.php?post_type=$matches[2]&taxonomy=$matches[1]','top');

}

add_action('init','your_plugin_rewrite_rule');

(OR)

RewriteEngine开启

RewriteCond%{QUERY_STRING} ^(。)ortregion(。)$

RewriteRule / blog / category / familien / blog / category / familien%1ort%2

答案 2 :(得分:0)

您可以使用:

import java.net.URL;

[...]

URL url = this.getClass().getResource("/words.txt");
String absoluteDiskPath = url.getPath();