theHussle theHussle - 1 month ago 7
Apache Configuration Question

.htaccess 301 redirect not working correctly

I'm trying to setup an .htaccess file to redirect old urls which I have REMOVED the pages from the server (not sure if this is the problem). I'm trying to redirect the pages to the new page which has the same content. Can anyone tell me why this doesn't work? (I believe it should) followed several online guides.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/wheels_landing_page.php [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com/wheels_landing_page.php [NC]
RewriteRule ^(.*)$ http://example.com/wheelsLanding.php/$1 [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^example.com/dealerships.php [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com/dealerships.php [NC]
RewriteRule ^(.*)$ http://example.com/contact.php/$1 [L,R=301,NC]

Answer

Try with:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^wheels_landing_page\.php(.*)$ http://example.com/wheelsLanding.php$1 [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^dealerships\.php(.*)$ http://example.com/contact.php$1 [L,R=301,NC]
Comments