Toni Michel Caubet
Toni Michel Caubet

Reputation: 20173

Redirect rule not fired in htaccess

Any thoughts why this url example.com/hotelinfo.aspx?idhotel=2 is not redirecting to this one example.com/new-url using the following rule in my .htaccess?

Redirect 301 /hotelinfo.aspx?idhotel=2 http://www.example.com/new-url

Upvotes: 1

Views: 25

Answers (1)

anubhava
anubhava

Reputation: 785481

You cannot match query string using Redirect directive, use mod_rewrite rules instead.

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^idhotel=2$
RewriteRule ^hotelinfo\.aspx$ http://www.example.com/new-url? [L,R=302,NC]

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

Upvotes: 1

Related Questions