htaccess将一个URL重定向到具有Dynamic参数的URL

时间:2015-09-23 10:19:17

标签: .htaccess redirect

我正在尝试使用他们的参数将一些网址重定向到其他网址,我正在使用此规则执行此操作,但它不起作用,我做错了什么?

我有www.example.com/ranges/some-of-the-range这样的网址,我想将所有这些网址重定向到www.example.com/info/ranges/some-of-the-range

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(ranges/.+)$ /info/$1 [R=301,L,NC]
# non www to www Redirect
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Blog URL Issue
RewriteCond %{REQUEST_URI} !^/blog
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

还请建议以更专业的方式学习.htaccess。

1 个答案:

答案 0 :(得分:2)

不,您无法匹配RewriteCond %{HTTP_HOST}中的请求URI。这仅用于匹配Web请求的域名。

您可以遵守以下规则:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(ranges/.+)$ /info/$1 [R=301,L,NC]
相关问题