.htaccess working on remote server but does not work on localhost. Getting 404 errors on localhost

7,561

Solution 1

You have .htaccess in your app/ and app/webroot dirs, but nothing in your root directory.

You should have the file: /home/user/public_html/site.com/public/.htaccess

RewriteRule    ^$    app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1    [L]

OR

Change your docroot to

DocumentRoot /home/user/public_html/site.com/public/app/

Both of these answers are assuming public/index.php isn't running some sort of advanced routing on the URI. Having nested .htaccess files doing rewrites is messy though.

Solution 2

Your site is under /home/user/public_html/site.com/public.

It contains: index.php app cake plugins vendors

And your root .htaccess file is:

RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]

So this means: whatever it is, go to the webroot folder in your installation.

But I don't see any webroot folder. Am I missing something?

Share:
7,561

Related videos on Youtube

Afsheen Khosravian
Author by

Afsheen Khosravian

Updated on September 18, 2022

Comments

  • Afsheen Khosravian
    Afsheen Khosravian over 1 year

    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>
    
  • Afsheen Khosravian
    Afsheen Khosravian over 12 years
    My webroot folder is located: /home/user/public_html/site.com/public/app/webroot/. It contains "css css.php favicon.ico files img index.php js template". Thanks for your reply.