Debiprasad
Debiprasad

Reputation: 6183

301 Redirect using .htaccess does not work

Here is my rule in .htaccess file:

Redirect 301 /George-Nelson-Bench-CT3005-EDI6.htm?categoryId=-1 http://www.mydomain.com/proddetail.php?prod=George_Nelson_Bench

But this is showing a 404 error on my website.

Some other code on the .htaccess file is:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

Some other 301 redirection which works properly:

Redirect 301 /Modern-Classics_c8.htm http://www.mydomain.com/categories.php?cat=10
Redirect 301 /Sofas_c34.htm http://www.mydomain.com/products.php?cat=25
Redirect 301 /Bedroom_c2.htm http://www.mydomain.com/categories.php?cat=7

So, why the first 301 redirect rule is not working?
Any suggestions?

Upvotes: 1

Views: 106

Answers (1)

anubhava
anubhava

Reputation: 786289

Since you're anyway using mod_rewrite its better to replace mod_alias based code to mod_rewrite which is more powerful and flexible.

You first Redirect rule isn't working because you're using a query parameter. Replace that rule with this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+George-Nelson-Bench-CT3005-EDI6\.htm\?categoryId=-1\s [NC]
RewriteRule ^ /proddetail.php?prod=George_Nelson_Bench? [R=301,L]

Upvotes: 1

Related Questions