2014-09-18 39 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