2012-08-01 114 views
1

出於某種原因,這是不工作...簡單的.htaccess重定向不工作

Options +FollowSymLinks -MultiViews -Indexes 
RewriteEngine On 
RewriteBase/

Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url 

我不知道爲什麼......如果我更換URL正在與另一個不存在的一個(/的HelloWorld)重定向它可以很好地重定向到新的網址。

它是否捕捉到某些東西?我嘗試轉義(/modules.php\?name=News &文件=文章& sid = 179),但它沒有任何區別,仍然只是404s。

任何幫助表示讚賞!

+0

404s?哪個頁面重定向到 – 2012-08-01 04:44:11

回答

0

您無法匹配Redirect指令中的查詢字符串,您必須使用mod_rewrite和%{QUERY_STRING}變量。試試這個:

RewriteCond %{QUERY_STRING} name=News&file=article&sid=179 
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L] 
# There is a ? here to prevent query strings appending -----^ 
+0

謝謝,OK,終於讓我走了!除了現在的網址:http://www.mysite.com/a/new/url/?name=News&file=article&sid=179。如何在不粘貼舊內容的情況下讓網址成爲/新/舊網址? – user1556073 2012-08-01 16:38:34

+0

@ user1556073在'/ a/new/url'的末尾添加**?**,看起來像這樣:'RewriteRule^/?modules \ .php $ http://www.mysite.com/a/新/網址是什麼? [R = 301,L]' – 2012-08-01 17:38:54

+0

仍然會做同樣的事情......它將查詢添加到新URL的末尾。我只想要像重寫規則中那樣顯示簡單的新URL(我不希望查詢結束)。謝謝! – user1556073 2012-08-01 21:19:07