Forum Moderators: phranque

Message Too Old, No Replies

.htaccess problem by redirecting (301)

I am having problems with 301 redirection

         

Graniti Niti

11:34 am on Oct 19, 2009 (gmt 0)

10+ Year Member



Hi I have an application which uses opencart. I would like to make a 301 reditect in case the user types http://example.com. To be redirected in http://www.example.com (301 status code)

Here is my .htaccess content:

#Options +FollowSymlinks

<IfModule mod_rewrite.c>

RewriteEngine On

#OPENCART REWRITES START

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*) index.php

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

#OPENCART REWRITES END

</IfModule>

I am getting 302 status code.

Thanx,
Granit

[edited by: phranque at 1:42 pm (utc) on Oct. 19, 2009]
[edit reason] exemplified domains [/edit]

phranque

1:44 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], Granit!

what type of url are you requesing?
what type of url are you redirecting to?
could there be additional redirection directives in the apache config file?
could that index.php script be returning a 302 response?

jdMorgan

1:53 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whether or not it fixes your problem, you should place your domain canonicalization redirect rule before your cart rewrite rule -- reversing the order of the rules shown above. Otherwise, your redirect will "expose" the internal filepath to "index.php" whenever it is invoked on a cart URL request.

In general, you should always place your external redirect rules first, in order from most-specific (one or a few URLs affected) to least specific (more URLs affected), followed by internal rewrites, again in order from most- to least-specific.

Jim