Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento URLs other than home page do not work without index.php

My magento is installed on Ubuntu Linux under /var/www/magento . This question looks like some of the questions in the archives but is acutally somewhat different. When I installed Magento on Ubuntu Linux I enabled Apache mod_rewrite URL rewrites.

When I go to http:// localhost/magento my server rewrites the URL as http:// localhost/magento/ and displays the page. I then click on one of the links in the navigation bar, let's say it's nav-bar item "foo". Then magento takes me to:

http:// localhost/magento/foo.html

which displays a "Not Found" apache page.

I have to change the URL to ----->

http:// localhost/magento/index.php/foo.html

in order to display the page.

It is as though something is amiss in my mod_rewrite workings.

Thanks,

John Goche

CONFIGURATION: System -> Configuration -> (General ->) Web:

Use Web Server Rewrites: YES

Base URL: http:// localhost/magento

If I set "User Web Server Rewrites:" to NO, then the links from my main page work fine, but see the page http:// localhost/magento/index.php/foo.html which displays the correct page, but whereas the website works I don't like the URL. I would like it to be http:// localhost/magento/foo.html without the index.php bit, as this would also probably be more SEO-friendly.

THanks,

John Goche


Update: I've tried uncommenting my artificial 127.0.1.1 IP address which ubuntu had put in /etc/hosts and placing ther my real IP but no luck. I still have exactly the same problem. And the URL inside my browser is rewritten to http:// localhost / etc... whenver I type 192.168.3.31, avalanche, or avalanche.com inside it. I am still trying to figure out how to solve the problem described above as this did not do it.

127.0.0.1       localhost
#127.0.1.1      avalanche

192.168.4.35    avalanche avalanche.com

When I restart Apache I get:

# service apache2 restart
 * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.4.35 for ServerName
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.4.35 for ServerName

Not sure how to fix the original issue. I am testing on a local server.


I've even tried this solution and then restarted apache2, but no luck!

How to remove index.php from URLs?

so placing:

RewriteEngine On
RewriteBase /mymagento/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

does not work, even with RewriteBase /, it does not work.


OK, finally I managed to solve the probkem. The file /etc/apache2/sites-enabled/000-default has the following directive set for all directories defined within this file:

 AllowOverride None

For instance, for /var/www which is the default document root set on Ubuntu 12.04 LTS Linux system this file contains

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

which as far as I understand means that .htaccess files found in this directory and all of its subdirectories will not be parsed. To fix the problem it is sufficient to set:

AllowOverride All

meaning you will be able to override the server configuration directives found in /etc/apache2/apache2.conf (or /etc/apache2/httpd.conf which is included therein).

One of the reasons AllowOverride is set to None by default could be that it slows down the server and the other is for security reasons. This directive should be set inside a tag and the latter ones can override the former. Another reason this is not set by default is that having to parse .htaccess recursively across the site each time a file in a directory path is loaded can slow down the system and thus placing the .htaccess stuff in /etc/apache2/httpd.conf when possible is recommendable as it can cause an increase in speed.

So place

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            #AllowOverride None
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

inside /etc/apache2/sites-enabled/000-default

and run: service apache2 restart

is the solution.

like image 899
user1527429 Avatar asked Jul 28 '12 16:07

user1527429


2 Answers

Did you try:

RewriteBase /magento/

and not RewriteBase /mymagento/ because your url is http:// localhost/magento/

Does your apache virtual host allow to overwrite the config, e.g.

<VirtualHost *:80>
...
<Directory /var/www/magento/>
    AllowOverride All
</Directory>
</VirtualHost>
like image 59
Sylvain Rayé Avatar answered Oct 07 '22 07:10

Sylvain Rayé


Do you have the appropriate .htaccess file in your Magento root? Also, you may run into issues with localhost. It's advised to use 127.0.0.1 or to map dev domains in your hosts file.

like image 24
benmarks Avatar answered Oct 07 '22 07:10

benmarks