2016-10-22 59 views
1

我有大約50箇舊鏈接將被重定向到新的鏈接。但是,我沒有重新定向,而是發送到404頁面。301重定向通過.htaccess不起作用

這是我下面的htaccess文件。任何想法我做錯了什麼?

## Mod_rewrite in use. 

RewriteEngine On 

## Begin - Rewrite rules to block out some common exploits. 
# If you experience problems on your site then comment out the operations listed 
# below by adding a # to the beginning of the line. 
# This attempts to block the most common type of exploit `attempts` on Joomla! 
# 
# Block any script trying to base64_encode data within the URL. 
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] 
# Block any script that includes a <script> tag in URL. 
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR] 
# Block any script trying to set a PHP GLOBALS variable via URL. 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
# Block any script trying to modify a _REQUEST variable via URL. 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
# Return 403 Forbidden header and show the content of the root homepage 
RewriteRule .* index.php [F] 
# 
## End - Rewrite rules to block out some common exploits. 

## Begin - Custom redirects 
# 
# If you need to redirect some pages, or set a canonical non-www to 
# www redirect (or vice versa), place that code here. Ensure those 
# redirects use the correct RewriteRule syntax and the [R=301,L] flags. 
# 
## End - Custom redirects 

Redirect 301 http://domain.me/blog.php?id=7 http://domain.me/blog 
Redirect 301 http://domain.me/iiblg/17-0-The-girl-with.html http://domain.me/blog/the-girl-with 
Redirect 301 http://domain.me/iiblg/20-0-Sendra-Lake.html http://domain.me/blog/sendra-lake 

還有更多的鏈接。我只是從這裏刪除它。

+0

是否啓用的.htaccess? – mrid

+0

是的,我確實啓用了它。 –

回答

0

您無法使用Redirect指令與查詢字符串進行匹配。你需要使用mod-rewrite來做到這一點。

重定向example.com/blog.php?id=7example.com/blog你需要以下規則:

RewriteEngine on 

RewriteCond %{QUERY_STRING} ^id=7$ 
RewriteRule ^blog\.php$ http://example.com/blog/? [NC,L,R] 
+0

謝謝,但其他鏈接會是什麼樣子?其他兩個鏈接,因爲這是其餘網址的格式。 –

+0

對於沒有查詢字符串的鏈接,可以使用Redirect指令(舊路徑不能以主機啓動),**重定向301 /dir/filename.html http://example.com/newfilename/** – starkeen

+1

謝謝。得到它完美的工作。不知道主機名。 –