Why is my .htaccess file redirecting to full server path instead of relative path?
Posted
by death.au
on Stack Overflow
See other posts from Stack Overflow
or by death.au
Published on 2010-03-30T04:08:27Z
Indexed on
2010/03/30
4:13 UTC
Read the original article
Hit count: 287
I've never had a problem with cakePHP before, but something's odd about this server and is causing the redirects in the .htaccess files to behave oddly.
CakePHP uses mod_rewrite in .htaccess files to redirect requests to its own webroot folder. The problem is that the redirects are listing the wrong path and causing a 404 error. My CakePHP application, which is stored in the listings directory, has a .htaccess file as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [R=301,L]
RewriteRule (.*) app/webroot/$1 [R=301,L]
</IfModule>
(*note that the R=301 causes an external redirect so we can see what is going on from our end. It should really omit this flag and do the redirect internally, transparent to end-users)
This is supposed to redirect any request from http://hostname.com/~username/listings/
to http://hostname.com/~username/listings/app/webroot/
However, rather than simply adding “app/webroot/
” to the end as it is supposed to, it is adding the full server path ( /home/username/public_html/listings/app/webroot/
) resulting in the final URL http://hostname.com/home/username/public_html/listings/app/webroot/
which is obviously incorrect and triggers a 404 error.
The hosting is on a shared hosting account, so that limits what I can do with the settings. I've never seen this happen before, and I'm thinking it's something wrong from the hosting side of things, but if anyone has some helpful suggestions then I can put them to the hosting company as well.
© Stack Overflow or respective owner