View Full Version : 301 redirects for www and non www issue

05-07-2011, 02:38 PM
i set up a redirect in my root htaccess to direct all non www to www.mysite.com (http://www.mystore.com)

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

### re-direct index.php to root / ###
RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

RewriteCond %{http_host} !^www.mysite.com$ [nc]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [r=301,nc,L]and i have this in my admin htaccess

AuthName "xxx"
AuthUserFile "/xxxx/txxxx/.htpasswds/public_html/admin/passwd"

RewriteEngine off
AuthType Basic
require valid-usereverything works fine until i password protect my admin folder then when i try to access my admin i get

401 Authorization Required

Invalid login credentials!

it never even gives me a box to enter my login info?

i dont know what im doing wrong but im missing something somewhere.

05-08-2011, 10:28 AM
also when i add the above to my htaccess it breaks the SEO urls

all the info i have searched shows to do it the way i have it above?
is there another way to write to the htaccess file that works correctly?

05-08-2011, 09:55 PM
NM - i got it working.

05-01-2012, 06:12 AM
how did you fix this one?
I'm having the same issues :)

05-01-2012, 07:07 AM
Hi There!
I'm trying to set up a proper 301 redirect to avoid canonical url problems with Google.
Setting up these within .htaccess into root will give me the problems:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{http_host} ^mysite.com [nc]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]

# REDIRECT /folder/index.php to /folder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.mysite.com/$1 [R=301,L]
The issues :
-seo url won't work anymore, all links will be like index.php/etc etc
-can't login to Admin anymore, the login page shows well, but it has the www.mysite.com/admin
and it's not recognizing the passwords
Any idea on where i can be wrong?
I have the same code running on oscommerce and works like a charm :|

05-01-2012, 09:38 AM
osCmax has canonical URLs built in! You don't need .htaccess as it done through the META tag - have a look at the page source.


05-01-2012, 12:56 PM
Hi Pg,
you and ridex are the stones of the forum with Michael :)
I tried to do that because i submitted the website to Virante High Potential Web Marketing (http://www.virante.com) and it gave me that sort of error (duplicate content errors)
On my "old" oscommerce website that worked well, and i wanted to have the www.website.com instead of website.com as suggested by the site.
That's it :P

05-01-2012, 02:31 PM
Okay ... I have just committed code for this for .htaccess into the core.

0001191: non-www redirect to www - osCmax Bug Tracking System (http://bugtrack.oscmax.com/view.php?id=1191)


05-02-2012, 03:39 AM
how about adding also this one?

# REDIRECT /folder/index.php to /folder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.%{HTTP_HOST}/$1 [R=301,L]

and for the "non-www" version

# REDIRECT /folder/index.php to /folder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

05-02-2012, 03:44 AM
Tested, the Admin side is not working properly, won't allow access (pass/user not recognized) :confused:
The Catalog part looks fine :)

05-04-2012, 02:12 AM
Hi PG,
i went to the bugtracker but this looks solved while it's not, how can i re-open the bug?

05-06-2012, 09:37 AM
Hi PG,
i see that in the Bugtracker the issue is closed, but testing it with the inserted code it causes admin login problems. Is there a way to re-open it so we can find a fix?

05-06-2012, 11:00 AM
Not sure what the issue is here ... don't know why catalog redirects and admin does not!

Anyway I have reopened the issue ... 0001191: non-www redirect to www - osCmax Bug Tracking System (http://bugtrack.oscmax.com/view.php?id=1191)

Going to need the community to help on this one as I can't see why it isn't working.


05-07-2012, 04:52 AM
Hi Pg,
i wish to help more, the admin redirects to the "www" but the login is not working...i'll investigate more on this too :)

05-08-2012, 05:00 AM
Oh I am also looking for same code of redirection as I have tried myself but something goes wrong. Anyway thanks a lot friends for this.