2016-03-24 29 views
0

基本上我想做一個301重定向從一個具有問號字符(?)在URL中的特定動態頁面到一個靜態頁面。如何逃避301重定向htaccess中的單個問號

我想這樣做的原因是,此頁面對搜索引擎優化有效,但它現在將從其自己的頁面中受益。我已經使用Rewrite規則多次重定向查詢字符串,但我似乎無法想象如何逃避,比如說,具有?的特定url。例如:

Redirect 301 /page.php?page_id=1 /new-page/ 
Redirect 301 /page.php?page_id=10 /cool-product/ 

我並不需要做到以下幾點:

RewriteRule ^page/([0-9]+)/([a-zA-Z0-9_-]+)/$ ./page.php?page_id=$1 [R=301,L] 

回答

1

你不能重定向URL使用Redirect指令查詢字符串到一個靜態頁面,則需要使用mod-rewrite,那麼試試這個:

在目標網址的結尾
RewriteEngine on 

RewriteCond %{THE_REQUEST} /page\.php\?page_id=1 [NC] 
RewriteRule^/newpage/? [L,R] 
RewriteCond %{THE_REQUEST} /page\.php\?page_id=10 [NC] 
RewriteRule^/anotherpage/? [L,R] 

空問號是很重要的,因爲它丟棄來自新老查詢strins網址。

0

條,與您從現在開始所有查詢字符串=只有在請求URI是公告/並重定向到/廣告/ URI:http://www.example.com/classifieds/?do=detailpage&cat=3&id=14http://www.example.com/ads/

# Redirects ONLY if the URI is classifieds/ and Strips the do= Query Strings 
# from the destination /ads/ URL|URI 
RewriteCond %{QUERY_STRING} ^do=(.*)$ [NC] 
RewriteRule ^classifieds/$ http://www.example.com/ads/$1? [R=301,L]