2016-10-22 3 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=7 к example.com/blog вам нужно следующее правило:

RewriteEngine on 

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

Спасибо, но как будут выглядеть другие ссылки? 2 других ссылки, так как это формат остальных URL-адресов. –

+0

Для ссылок без querystring вы можете использовать директиву Redirect (старый путь не может начинаться с хоста), ** Перенаправить 301 /dir/filename.html http://example.com/newfilename/** – starkeen

+1

Спасибо. Получил это отлично. Не знал о имени хоста. –