2016-05-20 94 views
1

你好,我想一些動態URL重定向到一些靜態URL 如htaccess的動態網址重定向

  • /folder/index.php?rid=321

  • http://example.com/folder/some-name-321.htm

  • /folder/index.php?rid=324

  • HTTP://example.com/folder/some-other-name-324.htm

我試圖

Redirect 301 /folder/index.php?rid=321 http ://example.com/folder/some-name-321.htm 
Redirect 301 /folder/index.php?rid=324 http ://example.com/folder/some-other-324.htm 

但不工作。 我應該如何重定向這些網址 另外,我應該在哪裏放置我的htaccess文件。 這應該在/folder/.htaccess中,或者我應該將規則放在網站根目錄下的主htaccess文件中。

親切的問候

回答

0

你永遠無法匹配反對使用Redirect(MOD-化名)指令查詢字符串。爲了manipule查詢字符串,你需要使用mod-rewrite以下規則/root.htaccess

RewriteEngine on 


RewriteCond %{QUERY_STRING} ^rid=(.+)$ 
RewriteRule ^index\.php$ http://example.com/folder/some-name-%1.htm? [NC,L,R] 
+0

我想這一點,但無濟於事,嘗試此方法後,當我訪問/folder/index.php?rid=321忽略了最低重定向到http://example.com/folder/some-name-321.htm –

+0

好吧,我用了下面的RewriteCond%{QUERY_STRING}(^ |&)rid = 325($ |&) RewriteRule^folder/index \。 php $ /folder/some-name-325.htm [L,R = 301] 但它重定向到http://example.com/folder/some-name-325.htm?rid=325 雖然我只需要http://example.com/folder/some-name-325.htm –