2014-09-18 31 views
1

我重新曾经是一个.NET网站Apache服务器上使用WordPress一个新的网站,旧网页网址是这样的:如何重定向Page.aspx =

Page.aspx?p=70 

我需要301重定向的所有页面到新的漂亮的URL中使用的.htaccess

当我使用

Redirect 301 /Page.aspx?p=70 http://example.com/foobar 

它不工作,和WordPress将其发送到

/?attachment_id=70 

我的.htaccess看起来像这样

Redirect 301 /Page.aspx?p=70 http://example.com/foobar 

# 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 
+0

请分享您的整个.htaccess – Bjorn 2014-09-18 19:42:22

+0

@Bjorn我已经添加了.htaccess现在 – user2520794 2014-09-18 20:06:03

回答

0

有这样说:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} ^p=70$ [NC] 
RewriteRule ^Page\.aspx$ /foobar? [L,NC,R=301] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

请记住,%{QUERY_STRING}没有使用Redirect指令匹配。

+0

是的这有效!谢谢!你知道70页这样做会不会有问题? – user2520794 2014-09-18 22:36:59

+0

70号对于重写规则来说并不是那么重要。我见过1000多条这样的规则。您也可以通过点击我答案左上角的刻度线来将答案标记为已接受。 – anubhava 2014-09-18 22:39:22