Zen Cart Logo
Forums / General Questions / Cannot log in after adding www. redirect to .htaccess file

Cannot log in after adding www. redirect to .htaccess file

Views: 3,179

Results 1 to 20 of 35
14 Dec 2012, 9:47 PM
#1
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Cannot log in after adding www. redirect to .htaccess file

I modified my .htaccess file so that non-www redirects to www. I now cannot log in to my admin page.

Here is the code I added:

# Always use www in the domain
# Replace 'example.com' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?toolsforchrist\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1toolsforchrist.com%{REQUEST_URI} [R=301,L]

Did I do something wrong, or is there something I need to change now?

Thanks
Corey

15 Dec 2012, 8:25 AM
#3
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

You should be insuring that in your configure.php files that you specify https://www.domain.com

16 Dec 2012, 2:50 AM
#4
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

Just did it, thanks. What does this do?

16 Dec 2012, 4:01 AM
#5
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

Just did it, thanks. What does this do?
It eliminates the need for a redirect

17 Dec 2012, 2:38 AM
#6
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

Aafter making the change to the config.php file I cannot log in to my admin. Is it important to make this change?

17 Dec 2012, 4:17 AM
#7
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

coreyalderin:

Aafter making the change to the config.php file I cannot log in to my admin. Is it important to make this change?

There are two ways to achieve your aim.

  1. Configure zencart so that the redirect isn't needed in the first place.
  2. Modify the .htaccess file so that the server performs a redirect to compensate for the incorrect zencart configuration.

One of these methods is going to cause a lot more headaches and problems down the track than the other.

Most people appear to prefer to use the method that will cause themselves the most problems. Something I will never understand!

Cheers
Rod

ps. Redirects are inherently bad! It is the equivalent of giving someone your shop address, but when they go to the shop they are greeted with a 'we have relocated' message. Very frustrating for the customer, and if google were the customer I'm sure it wouldn't give very good rankings to a site that effectively no longer exists. :)

17 Dec 2012, 8:14 PM
#8
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

I dont know about everyone else, but the reason I have done what I am assuming is the "headache" way, is because all the research I have done seems to say doing it this way is best. There is just so much to learn with Zen-cart that it would be impossible for the majority of newbees to get everything right.

What is the best way to do it?

17 Dec 2012, 8:19 PM
#9
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Cannot log in after adding www. redirect to .htaccess file

The best way to do it, IMO, is to install Zencart in the root directory of your domain and dispense with the redirects. If you have information to the contrary, I'd be interested in seeing it.

17 Dec 2012, 10:33 PM
#10
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

How do you do the redirects? Here is what I have tried so far:

First I tried adding some code that my host told me to include into the .htaccess file. I cannot remember the code. But that caused a problem in logging into to the admin page.

Then I changed that code to the below code, which was referenced here: http://www.zen-cart.com/showthread.php?134860-Cant-login-to-admin-after-301-redirect-htaccess

RewriteEngine ON
 
## removes www from Browser URL
 RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
 RewriteRule ^(.*) http://yourdomain.com/$1 [R=301,L]

That worked. But then I was told that it was best to change the configure.php file. So then I did that with the additions in red below:

/**
 * WE RECOMMEND THAT YOU USE SSL PROTECTION FOR YOUR ENTIRE ADMIN:
 * To do that, make sure you use a "https:" URL for BOTH the HTTP_SERVER and HTTPS_SERVER entries:
 */
  define('HTTP_SERVER', 'http://www.toolsforchrist.com');
  define('HTTPS_SERVER', 'https://www.toolsforchrist.com');
  define('HTTP_CATALOG_SERVER', 'http://www.toolsforchrist.com');
  define('HTTPS_CATALOG_SERVER', 'https://www.toolsforchrist.com');

Now it redirects correctly, but I cannot log into my admin page

17 Dec 2012, 10:39 PM
#11
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

Now it redirects correctly, but I cannot log into my admin page
Did you remove the htaccess redirect after editing your 2 configure.php files??

17 Dec 2012, 10:49 PM
#12
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

stevesh:

The best way to do it, IMO, is to install Zencart in the root directory of your domain and dispense with the redirects. If you have information to the contrary, I'd be interested in seeing it.
I agree the proper way is to have the correct values in the two (one in the catalog one in the admin) configure.php files.

Additionally using the .htaccess 301 redirect is not a bad thing (just another piece to remember or document for future reference). There are at least two cases I can think of (off the top of my head) where having the 301 is beneficial.
1) To force the redirect for the first incoming page visited / crawled. Such as the home page or URLs already indexed by SEs.
2) When your site is visible from more than one hostname. This is a little complicated to set up (is not to my knowledge supported by the Zen Cart team) and I would not recommend setting this up unless you have a really good reason to do so. There are compelling reasons you should not be doing this (but sometimes you have no option).

That said two of the usual problems people run into are when working with RewriteRules and "R=301" or "R" is post data will usually be lost (so you need to check if the request is a POST before redirecting) and without the "QSA" flag query parameters may be discarded.

17 Dec 2012, 11:04 PM
#13
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

First I would ask was this an upgrade from Zen Cart 1.3.x to 1.5.x? If you upgraded without removing your old admin configure.php you may need to adjust some additional variables relating to the location of the admin folder.

Second are there any error logs (apache error log, Zen Cart debug logs in "cache" or "logs" folder)?

# Rewrite host name to FQDN
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)$ http://www\.%{HTTP_HOST}$1 [R=301,QSA,L]

define('HTTP_SERVER', 'http://www.yourdomain.com');
define('HTTPS_SERVER', 'https://www.yourdomain.com');
define('HTTP_CATALOG_SERVER', 'http://www.yourdomain.com');
define('HTTPS_CATALOG_SERVER', 'https://www.yourdomain.com');

Note the two methods must match. If you are adding the "www." then your defines should have the "www.".
If you are removing the "www." then your defines should not have the "www.".

You may also want to check if the request was "https" and redirect appropriately if it was. This means messing around more with RewriteConds.... And at least two RewriteRules. As you can see utilizing RewriteRules can sometimes be complicated.

17 Dec 2012, 11:24 PM
#14
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

kobra:

Did you remove the htaccess redirect after editing your 2 configure.php files??

Yes. the configure.php files that I edited where in the /admin/includes (4 locations that I added "www.") the /includes folders (2 locations that I added "www."). Is that correct?

17 Dec 2012, 11:28 PM
#15
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

But Did you remove the htaccess redirect ?

17 Dec 2012, 11:32 PM
#16
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

lhungil:

First I would ask was this an upgrade from Zen Cart 1.3.x to 1.5.x?
No

lhungil:

Second are there any error logs (apache error log, Zen Cart debug logs in "cache" or "logs" folder)?
I don't know how to do this. Is there somewhere you can point me to read up on this?

lhungil:

Note the two methods must match. If you are adding the "www." then your defines should have the "www.".
If you are removing the "www." then your defines should not have the "www.".

What do you mean "your defines"?

Thanks for all the responses

17 Dec 2012, 11:32 PM
#17
coreyalderin avatar

coreyalderin

Zen Follower

Join Date:
May 2012
Posts:
137
Plugin Contributions:
0

Re: Cannot log in after adding www. redirect to .htaccess file

kobra:

But Did you remove the htaccess redirect ?

Yes, sorry for not being clear about that.

17 Dec 2012, 11:40 PM
#18
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

What do you mean "your defines"?
In your configure.php files

  [B]define[/B]('HTTP_SERVER', 'http://www.your_domain.com');
  [B]define[/B]('HTTPS_SERVER', 'https://www.your_domain.com');

I don't know how to do this. Is there somewhere you can point me to read up on this?
For debug files use FTP and look at /cache or /logs

18 Dec 2012, 3:48 AM
#19
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

lhungil:

Additionally using the .htaccess 301 redirect is not a bad thing

301 redirects have their place, but using them on a NEW site means one thing and one thing only. The site hasn't been setup correctly in the first place.

lhungil:

There are at least two cases I can think of (off the top of my head) where having the 301 is beneficial.

Hopefully you can think of more than just these two, because neither of those you are valid reasons to use a redirect on a new site.

lhungil:

1) To force the redirect for the first incoming page visited / crawled. Such as the home page or URLs already indexed by SEs.

For this to be beneficial would mean that the site was originally set up incorrectly which caused the 'wrong' URL's to be indexed, and the 301 redirect is a method of fixing the original error. It is better to set the site up correctly in the first place so the 'wrong' URL's don't get indexed, and therefore there will never be a need for this redirection fix.

lhungil:

2) When your site is visible from more than one hostname.

Such as "www.mydomain.com" and "mydomain.com" ?

Is a redirect really needed in this instance? No. Doing so will defeat the point of having the site 'visible from more than one hostname'. A URL rewrite is a much more suitable candidate to use than a redirect in this instance, but either way after the 1st site access all other zencart links are dynamically created according to the configuration files, so neither method offers any practical gains, as both methods are essentially competing with zencarts' internal functionality.

Don't fall for the misinformation presented by several of the most popular site validation services that loudly complain that it is a bad thing if www.mydomain.com and mydomain.com don't resolve to the same page/site. This is NOT a bad thing. They are technically different hosts, and as such there is no logical or practical reason for both hosts to serve the same data. The exception being when the 'www' is defined as an alias (CNAME) of the main domain (in which case they should both serve the same data), and THIS being the case, we still don't need a redirect or rewrite because the DNS will connect the client with the correct server as part of its normal functions.

So, once again, I shall repeat my stance, if you are setting up a new site, and the first thing you think you need to do is add some sort of redirection to get things to work then take a step back.. you are almost certainly heading in the wrong direction.....

Redirects and rewrites do have thier place. They wouldn't have been created otherwise, but I sure wish people would do themselves a favour and not use this 'sledge hammer' method when using a screwdriver will suffice. :)

Cheers
Rod

18 Dec 2012, 5:42 AM
#20
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Cannot log in after adding www. redirect to .htaccess file

On Topic
You can contact your webserver hosting provider for help locating any webserver error logs. There is usually a place in cpanel (or the provided control panel) where you can view these... and some hosting providers write them to a folder accessible via FTP... although sometimes they are disabled by hosting providers for performance reasons.

Some more questions... Sorry if already answered - just asking for clarification.
Can you get to the login screen in the admin?
You said after removing your changes to the .htaccess file you still cannot login to the admin?
If you remove the .htaccess file can you successfully login to the admin?
Have you tried the steps listed in this article pertaining to fixing admin login issues?

Any additional information you can provide about what may have changed on your site from when you could login to now will help the nice people here on the forums aid you.

Off Topic (but answering some questions asked in this thread)

RodG:

Redirects and rewrites do have thier place. They wouldn't have been created otherwise, but I sure wish people would do themselves a favour and not use this 'sledge hammer' method when using a screwdriver will suffice. :)
Agreed. Thus why I said the best fix was to update the define entries in the respective configure.php files. I'm sure you have seen people do some crazy things with redirects... everything from minor performance hits all the way to the point of harming their SE ranking and website. I know I have.

However my original point is having the additional redirect (setup correctly) will not cause any harm (if Zen Cart is configured correctly). I also wanted to point out two cases (off the top of my head) where adding a redirect related to the FQDN may have benefit (as someone asked the question). I would be remiss if I did not point out this article on the Zen Cart website currently recommends adding the redirect and gives a reason why it may be beneficial.

RodG:

For this to be beneficial would mean that the site was originally set up incorrectly which caused the 'wrong' URL's to be indexed, and the 301 redirect is a method of fixing the original error. It is better to set the site up correctly in the first place so the 'wrong' URL's don't get indexed, and therefore there will never be a need for this redirection fix.
Exactly my point for case 1). Sometimes you pick up an existing site and may wish to use a redirect to let SE's and browsers know which address they should use (when you want to change the URL shown / linked to from a SE). Or you may want to "help" any users who are typing your website into the address bar. Or you may be migrating to a new FQDN (although I would take every step possible to avoid ever changing the FQDN of a well established website).

Of course canonical links also provide this information to SEs (and are already present in current versions of Zen Cart) and help stop most SEs from considering "www.yoursite.com" and "yoursite.com" as duplicate content / separate websites. Browsers typically do not care about duplicate URLs. In my experience when you want to change the URL shown / linked to from a SE (I will not claim to be an expert) 301 redirects tend to be picked up faster by SEs than canonical links.

At the time I posted I did not know the site was new, thus why I asked the OP if they were working on a Zen Cart upgrade or a new installation. For a site with little link juice the 301's are overkill (and can be a hassle), other then as a proactive step once everything with Zen Cart is working.

RodG:

Such as "www.mydomain.com" and "mydomain.com"?
Nope. Again as I said, case 2) is not something I would recommend or something 99.9% of people need to worry about. If you really want to know more I can explain the use cases in a PM. But I know you are a bright person (who is also good at debating) and can probably figure most of these out. They do not apply to the OPs problem.