Rizwan Ranjha
Rizwan Ranjha

Reputation: 380

htaccess redirect to one URL to an URL with Dynamic parameter

I am trying to redirect some urls to some other urls with their parameter, I am doing this with this rule but its not working, am I doing something wrong?

I have URLs like www.example.com/ranges/some-of-the-range and I would like to redirect all these to 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>

Please also suggest to learn .htaccess in more professional way.

Upvotes: 1

Views: 293

Answers (1)

anubhava
anubhava

Reputation: 785146

No you cannot match Request URI in RewriteCond %{HTTP_HOST}. That is used to match domain name only for a web request.

You can have your rule like this:

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

Upvotes: 2

Related Questions