Help with cake php (htaccess nightmare)

I have taken over a site created with cake php and I haven’t a clue about cake php - there appears to be htaccess files everywhere! I need to keep the site ticking over while I get up to speed with cake php and one thing I need to do is install a webstats app.

My hosting account has a one click install for both webalizer and awstats and I have tried both

http://www.mysite.com/webalizer
http://www.mysite.com/awstats

Problem is I get the following error for both



The page isn't redirecting properly         

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    *   This problem can sometimes be caused by disabling or refusing to accept
          cookies.


I googled this and found the following solution which didn’t work - same error as before.

modify the .htaccess file in app/webroot.



<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond &#37;{REQUEST_URI} ^/awstats/(.*)$
    RewriteRule ^.*$ - [L]
</IfModule>
# Begin CakePHP
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>



I would really appreciate any advice on how to get one of these stats to work.

Thanks

Paul

You’ll need to add those lines to all of the .htaccess files that CakePHP uses. Try adding them in /.htaccess, /app/.htaccess, /app/webroot/.htaccess.

Also, the Rewrite Base statement is only needed for some hosts such as GoDaddy who actually serve your pages from a user directory (http://example.com/~username/cakephp/).

Thank you so much ditch182 - I did as you suggested and it now works - phew!

I noticed that the htaccess file in the root already had something similar for the forum



<IfModule mod_rewrite.c>
  RewriteEngine  on
 RewriteCond &#37;{REQUEST_URI} !^/awstats/
 RewriteCond %{REQUEST_URI} !^/forum/
 RewriteCond %{REQUEST_URI} !^/forums/
 RewriteCond %{REQUEST_URI} !^/phpMyAdmin/
  RewriteRule ^$       app/webroot/     [L]
   RewriteCond %{REQUEST_URI} !^/awstats/
   RewriteCond %{REQUEST_URI} !^/forum/
   RewriteCond %{REQUEST_URI} !^/forums/
   RewriteCond %{REQUEST_URI} !^/phpMyAdmin/
  RewriteRule ^(.*)$ app/webroot/$1  [L]
  
  
</IfModule> 



It is like japanese to me all this htaccess code:)

I know what you mean. I’ve been there myself.

I’ve been looking for this exact solution off and on for some time now and I had added the above rules to the .htaccess file in the root of the CakePHP site and was still getting errors.

I have now added these rules to the .htaccess files in /app and /app/webroot and it still wont let me login to awstats. Instead I get redirected to Cake’s error 401.

Funny thing is even with just those rules in the .htaccess and root if I turn debug to 1 in /app/config/core.php I can login fine and can then turn debug back to 0 and use awstats fine for that login session, but that’s obviously not a workable solution for the client :frowning:

Any ideas? I’m using Cake 1.2.5

I have seen reports of some users having to modify the root .htaccess file instead of the one in app/webroot. Try modifying /.htaccess with the same code and see what happens.

Sorry, meant to say in yesterday’s post that I had added it to all 3, not sure why I only mentioned two :?

So, the reason you’re seeing the 401 error is that Cake checks for the existence of a file before invoking the redirection.
However, that shouldn’t be happening if the root .htaccess is written properly.

A couple of things to try:
Check your modifications and make sure that all of the folder names are correct. For instance, my sites have awstats located in the directory “www.example.com/stats” while some may have them in “www.example.com/awstats”.

Remove the following statement:
RewriteBase /

Try this at the beginning of /.htaccess
RewriteCond %{REQUEST_URI} ^/awstats/
RewriteRule ^$ path/to/awstats [L]

Finally remember that Mod_ReWrite uses physical paths (like /usr/bin/htdocs/index.html) that don’t always relate to web directory structures.

Thanks for taking the time to help me with this :slight_smile:

I’m confident the rewrite rule itself is correct as if I set Config.debug to 1 in /app/core.php I can login to awstats without issue. It;s only when debig is set to 0 that I get the 401 error?!?

How do you access awstats? Is it something like
www.example.com/cgi-bin/awstats.pl?config=example.com

If that’s how you access it, is the cgi-bin password protected?

I access at www.site.com/awstats and it’s password protected by configuration of the within plugin section of DirectAdmin.

Do you have awstats password protected on your installations that work?

I’m wondering if it’s a simlink issue that cakephp doesn’t like. Awstats is a perl script, so it’s probably physically located in /cgi-bin. If logging in through site.com/awstats actually redirects through site.com/cgi-bin/awstats.pl then you may need to add something like

RewriteCond %{REQUEST_URI} ^*/awstats/
RewriteRule ^$ path/to/awstats [L]

Have you looked at app/tmp/logs/debug.log to see if there’s anything there?

At this point, I’m out of ideas. Good luck, and I hope you figure it out.

I’ve now posted this on the google group as I found more info on stackoverflow related to this issue. Fingers crossed someone will chime in with a solution.

http://groups.google.com/group/cake-php/browse_thread/thread/c6e48db71efbb81d