2016-09-28 95 views
0

我正在将ASPX站点移动到Wordpres - 从IIS服务器到Apache - 并且在查询字符串重定向页面时遇到问题。我查看了Apache文档,并试图使用mod_rewrite,但至今没有运气。为什么我的htaccess RewriteRule不能用于查询字符串?

比如我想重定向这些页面:

www.mysite /产品/ Product.aspx的azazaz = 324 $到 www.mysite /蓝色的小部件/ widget7/ www.mysite /Product/Product.aspx?mapid=681$至 www.mysite/blue-widgets/widget82/ www.mysite/Product/Product.aspx?mapid = 841 $至 www.mysite/blue-widgets/widget82/

这里是我在哪里。我已经尝试了几次迭代,但无法使其工作。我开始认为它可能与前几个规则有关,这些规则是由服务器和Wordpress生成的。该网站是一个附加域,服务器将其视为一个子域。

我的重写是最后三个。任何想法为什么这些不工作?谢谢你的帮助。

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /~username/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /~username/mysite/index.php [L] 

    RewriteCond %{QUERY_STRING} ^mapid=324$ [NC] 
    RewriteRule ^/Product/Product\.aspx(.*)$ ^https://www.mysite/blue-widgets/widget7/? [L,R=302,NC] 

    RewriteCond %{QUERY_STRING} ^mapid=681$ [NC] 
    RewriteRule ^/Product/Product\.aspx(.*)$ ^https://www.mysite/blue-widgets/widget12/? [L,R=302,NC] 

    RewriteCond %{QUERY_STRING} ^mapid=841$ [NC] 
    RewriteRule ^/Product/Product\.aspx(.*)$ ^https://www.mysite/blue-widgets/widget82/? [L,R=302,NC] 

</IfModule> 

回答

1

我相信下面的工作:

RewriteEngine On 
RewriteCond %{QUERY_STRING} ^mapid=324$ [NC] 
RewriteRule /Product/Product\.aspx https://www.example.com/blue-widgets/widget7/? [L,R=302,NC] 

RewriteCond %{QUERY_STRING} ^mapid=681$ [NC] 
RewriteRule /Product/Product\.aspx https://www.example/blue-widgets/widget12/? [L,R=302,NC] 

RewriteCond %{QUERY_STRING} ^mapid=841$ [NC] 
RewriteRule /Product/Product\.aspx https://www.example/blue-widgets/widget82/? [L,R=302,NC] 

RewriteBase /~username/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /~username/mysite/index.php [L] 

为了更好地解释给别人,规则的顺序很重要。由于Wordpress规则更改了RewriteBase并更改了URL,因此.aspx页面的规则如果位于底部,它们将永远不会被击中。

+0

因此,操作顺序很重要?将我的规则移动到RewriteBase上方?仍然似乎没有工作,但我会再玩一些。谢谢。 – jshock

+0

我也改变了你的规则。尝试我所拥有的。 – Fencer04

+0

谢谢。这工作。 – jshock

相关问题