Forum Moderators: phranque

Message Too Old, No Replies

htaccess file

htaccess file

         

Popus

7:34 pm on Jul 25, 2010 (gmt 0)

10+ Year Member



Hi all,
i have i probleme and i cannot find it, hope someone will help me :)
My htaccess file on my web root is as follow :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

# disable directory browsing -IMPORTANT, do NOT remove.
Options -Indexes

# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>

# disable the server signature
ServerSignature Off

# protect php.ini
<files *.ini>
order allow,deny
deny from all
</files>

-The problem is that my site is seen from "mydomain.com/public_html/app/webroot/" and i have a awstats folder in my root ("mydomain.com/public_html/awstats") that i cannot access.
When i try to access the folder awstats, i get back to the to my site.
Can someone tell me what rules i can put to get access to my awstats folder ? (that folder have password rights, etc and everything is okay)
regards

jdMorgan

8:41 pm on Jul 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace your two RewriteRules with this one:

RewriteEngine on
RewriteCond $1 !^app/webroot/
RewriteCond $1 !^awstats/
RewriteRule ^(.*)$ app/webroot/$1 [L]

Jim

Popus

1:09 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Hi, thanks Jim, but it did not work, i might do something wrong.
To help, i put my 3 htaccess files.

in "mydomain.com" :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
.
.
.

In "mydomain.com/app" i have
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

in "mydomain.com/app/webroot" i have :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

The folder i'm trying to have access is "mydomain.com/awstats"

hope this will help.
When i go to mydomain.com from the browser, i see "mydomain.com" but in reality i'm in "/app/webroot" because if a put a file in folder "page" like "mydomain.com/app/webroot/page/test.html", in my browser i have "mydomain.com/page/test.html"

Hope i'm not to confusing :)
thanks so much for any help

jdMorgan

2:43 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not clear whether you are using the code I recommended or not...

Delete (or comment out) the two rules in /app/.htaccess. They should not be needed at all, since these requests are handled by the rule in the /.htaccess file.

The code in /app/webroot/.htaccess can be improved for performance by excluding all filetypes that the "index.php" script cannot generate. For example, there is no need to check the hard drive for 'file exists' if the script cannot create an image file or a css stylesheet, or a PDF document. The more filetypes excluded, the fewer times the server will have to read your disk. So, for example, in /app/webroot/.htaccess:

RewriteEngine on
RewriteCond $1 !^index\.php$
RewriteCond $1 !\.(gif|jpe?g|png|css|js|doc|pdf|mp3|swf|flv|mov|wmv|avi)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

It is not critical to exclude *all* filetypes that the "index.php" script cannot create. It is only necessary to exclude the most-frequently-requested filetypes. The 'list' I show is just for illustration, and you should adjust it to suit your site.

The code appears to assume that the "index.php" file is located at /index.php and not at /app/webroot/index.php. Is that correct? If not, adjust the exclusion patterns and substitution paths.

Also, The <IfModule> containers are a waste of CPU time unless you want this code to fail silently on servers where mod_rewrite is not available -- rarely the desired behaviour.

Jim

Popus

6:09 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Thanks Jim,
i'm lost :) well, something is not going right. i put back my htaccess below:

in mydomain/
#<IfModule mod_rewrite.c>
# RewriteEngine on
# RewriteRule ^$ app/webroot/ [L]
# RewriteRule (.*) app/webroot/$1 [L]
#</IfModule>

RewriteEngine on
RewriteCond $1 !^app/webroot/
RewriteCond $1 !^awstats/
RewriteRule ^(.*)$ app/webroot/$1 [L]

RewriteCond $1 !^index\.php$
RewriteCond $1 !\.(gif|jpe?g|png|css|js|doc|pdf|mp3|swf|flv|mov|wmv|avi)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

in mydomain/app:
#<IfModule mod_rewrite.c>
# RewriteEngine on
# RewriteRule ^$ webroot/ [L]
# RewriteRule (.*) webroot/$1 [L]
#</IfModule>

in mydomain/app/webroot:
#<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
#</IfModule>

Note that my web is base on a script (cakephp). If it help, my website is at bidopus.ca, right now is offline but even if i put it online i still get back to the 'root'
thanks again :)

jdMorgan

8:15 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where is index.php located in the filesystem? Is it located in the server DocumenRoot, or in /app/webroot?

Jim

Popus

9:15 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Hi Jim,
First, in the root, i have a index.php as follow :

<?php
define('APP_DIR', 'app');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
//define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR';
define('CAKE_CORE_INCLUDE_PATH', ROOT);
}
if (function_exists('ini_set')) {
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS);
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
require CORE_PATH . 'cake' . DS . 'basics.php';
$TIME_START = getMicrotime();
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require LIBS . 'object.php';
require LIBS . 'inflector.php';
require LIBS . 'configure.php';

$bootstrap = true;
$url = null;
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
?>

The second index.php is in app/
<?php
require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
?>

and the third index.php in app/webroot is the main one.

thanks

jdMorgan

3:11 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, I would look at the RewriteRule substitution paths, and make sure that they specify the correct filepath to those scripts.

Jim