.htaccess working on remote server but does not work on localhost. Getting 404 errors on localhost
Posted
by
Afsheen Khosravian
on Server Fault
See other posts from Server Fault
or by Afsheen Khosravian
Published on 2012-01-01T16:26:56Z
Indexed on
2012/07/07
15:18 UTC
Read the original article
Hit count: 463
MY PROBLEM:
When I visit localhost the site does not work. It shows some text from the site but it seems the server can not locate any other files. Here is a snippet of the errors from firebug:
"NetworkError: 404 Not Found - localhost/css/popup.css"
"NetworkError: 404 Not Found - localhost/css/style.css"
"NetworkError: 404 Not Found - localhost/css/player.css"
"NetworkError: 404 Not Found - localhost/css/ui-lightness/jquery-ui-1.8.11.custom.css"
"NetworkError: 404 Not Found - localhost/js/jquery.js"
It seems my server is looking for the files in the wrong places. For example, localhost/css/popup.css is actually located at localhost/app/webroot/css/popup.css.
I have my site setup on a remote server with the same exact configurations and it works perfectly fine. I am just having this issue trying to run the site on my laptop at localhost. I edited my VirtualHosts file DocumentRoot and to /home/user/public_html/site.com/public/app/webroot/ and this reduces some errors but I feel that this is wrong and sort of hacking it since I didn't use these setting on my production server which works.
The last note I want to make is that the website uses dynamic URLs. I dont know if that has anything to do with it. For example, on the production server the URLS are: site.com/#hello/12321.
HERES WHAT I AM WORKING WITH:
I have a LAMP server setup on my laptop which runs on Ubuntu 11.10.
I have enabled mod_rewrite:
sudo a2enmod rewrite
Then I edited my Virtual Hosts file:
<VirtualHost *:80>
ServerName localhost
DirectoryIndex index.php
DocumentRoot /home/user/public_html/site.com/public
<Directory /home/user/public_html/site.com/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Then I restarted apache. My website is using cakePHP. This is the directory structure of the website: "/home/user/public_html/site.com/public" contains:
index.php app cake plugins vendors
These are my .htaccess files:
/home/user/public_html/site.com/public/app/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/home/user/public_html/site.com/public/app/webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
© Server Fault or respective owner