2012-09-04 39 views
0

與mod_rewrite的重定向我現在htaccess看起來像網址查詢(GET參數樣?ID = 5)htaccess的

DirectoryIndex welcome.do index.jsp default.php index.wml homepage.php default.htm default.html index.php index.php4 index.php3 index.htm index.html index.shtml default_new_vhost.html 

# 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 

RedirectPermanent /content.asp?AUID=01 /content/ 
... 

重定向不起作用(我只得到了404頁的WordPress)。原因是URL中的get參數。我試着回答here。例如。

RewriteCond %{REQUEST_URI} ^/content.asp$ 
RewriteCond %{QUERY_STRING} ^AUID=01$ 
RewriteRule ^.*$ http://www.yourdomain.com/content? [L,R=301] 

要麼我得到500錯誤,要麼我來到Wordpress的404頁面。這樣做的正確方法是什麼?比我在的形式

RedirectPermanent /content.asp?pCategory=&pCountry=1&AUID=01 /content/ 

這是不對的許多項目,但我尋找一個有效的方式把這個在htaccess的。我可以使用這樣的東西嗎?

RewriteCond %{REQUEST_URI} ^/content.asp$ 
RewriteCond %{QUERY_STRING} ^pCategory=([0-9]+)&pCountry=([0-6]+)$ 
RewriteRule ^.*$ http://www.yourdomain.com/content? [L,R=301] 

回答

0

你只需做到這一點(從我的網站)

rewriteCond %{QUERY_STRING} ^id=([0-9]+)$ 
rewriterule ^news_details.asp$ news/index.php?old_id=%1 

替換^ ID與任何PARAM和簡單的用戶%1%2訪問他們在重寫,你會

rewriteCond %{QUERY_STRING} ^pCategory=([0-9]+)&pCountry=([0-6]+)$ 
rewriteRule ^content.asp$ /content/?category=%1&country=%2 
+0

感謝您的建議。不知道這是可能的。 – testing

0

我結束了以下解決方案:

DirecotryIndex welcome.do index.jsp ... 

RewriteCond %{REQUEST_URI} ^/content.asp$ 
RewriteCond %{QUERY_STRING} ^AUID=01$ [OR] 
RewriteCond %{QUERY_STRING} ^pCategory=&pCountry=1&AUID=01$ [OR] 
RewriteCond %{QUERY_STRING} ^pCategory=&pCountry=8&AUID=01$ 
RewriteRule ^.*$ /content? [L,R=301] 

RedirectPermanent /italiano/index.asp /it/ 

# 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 

問題在於我將代碼放在Wordpress代碼之前,而不是之前。如果您將htaccess的編碼更改爲不含BOM的UTF-8,也可以使用變音符號。您也可以使用GET參數重定向到URL,而不會出現任何問題。