30

All of my URLs on my Magento installation require index.php in them, like:

http://example.com/index.php/admin/
http://example.com/index.php/customer/account/login/

The problem is that the system by default links to URLs like

http://example.com/admin/
http://example.com/customer/account/login/

Which look prettier anyway. I assume this is a rewrite issue in .htaccess, but as tinkering with that in the past has given me 500s, I'd like to ask you guys first.

Changing the SEO settings, flushing the configuration cache, and reindexing URLs did not work as suggested here.

Community
  • 1
  • 1
delwin
  • 830
  • 2
  • 10
  • 15

8 Answers8

86

Before you start, make sure the Apache rewrites module is enabled and then follow the steps below.

  1. Log-in to your Magento administration area then go to System > Configuration > Web.

  2. Navigate to the Unsecure and Secure tabs. Make sure the Unsecured and Secure - Base Url options have your domain name within it, and do not leave the forward slash off at the end of the URL. Example: http://www.yourdomain.co.uk/

  3. While still on the Web page, navigate to Search Engine Optimisation tab and select YES underneath the Use Web Server Rewrites option.

  4. Navigate to the Secure tab again (if not already on it) and select Yes on the Use Secure URLs in Front-End option.

  5. Now go to the root of your Magento website folder and use this code for your .htaccess:

    RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]

Save the .htaccess and replace the original file. (PLEASE MAKE SURE TO BACKUP YOUR ORIGINAL .htaccess FILE BEFORE MESSING WITH IT!!!)

  1. Now go to System > Cache Management and select all fields and make sure the Actions dropdown is set on Refresh, then submit. (This will of-course refresh the Cache.)

---------->

If this did not work please follow these extra steps.

  1. Go to System > Configuration > web again. This time look for the Current Configuration Scope and select your website from the dropdown menu. (This is of course, it is set to Default Config)

  2. Make sure the Unsecure and Secure fields contain the same domain as the previous Default Config file.

  3. Navigate to the Search Engines Optimisation tab and select Yes underneath the Use Web Server Rewrites section.

  4. Once the URLs are the same, and the rewrite is enabled save that page, then go back and make sure they are all checked as default, then save again if needed.

  5. Repeat step 6.

Now your index.php problem should be fixed and all should be well!!!

starball
  • 20,030
  • 7
  • 43
  • 238
Blowtar
  • 996
  • 9
  • 11
  • Does the order of lines matter? – NeoJi Oct 10 '14 at 14:34
  • I'm not sure if the order of lines matter, I wouldn't imagine it does in this scenario. To be safe I would keep the format as presented above as this seems to work for a fair amount of people. – Blowtar Oct 11 '14 at 21:12
  • 5
    Make sure `AllowOverride All` is on for your configuration otherwise your .htaccess file will get ignored. – beingalex Mar 16 '15 at 12:37
  • 5
    Re `AllowOverride All` in recent Ubuntu versions at least, that is added to `/etc/apache2/apache2.conf` ` Options Indexes FollowSymLinks AllowOverride All Require all granted ` Than restart Apache: `/etc/init.d/apache2 restart` – johnsnails Aug 23 '15 at 22:41
  • Sure, at least on Ubuntu 14.04, as default AllowOverride is none, so we need to change " Options Indexes FollowSymLinks AllowOverride None Require all granted " to " Options Indexes FollowSymLinks AllowOverride All Require all granted ", so as rewrite start to work – John Yin Nov 28 '15 at 12:55
  • 1
    I would upvote this answer 10x if I could :D Thanks @Blowtar! – djeison Dec 20 '15 at 20:02
  • OMG !!! Thanks John .... I was struggling to find it since 4 hrs. I am adding some more detail as answer below. you deserve upvote for it. – Suyash Kumar Bharti May 11 '16 at 07:18
23

Follow the below steps it will helps you.

step 1: Go to to your site root folder and you can find the .htaccess file there. Open it with a text editor and find the line #RewriteBase /magento/. Just replace it with #RewriteBase / take out just the 'magento/'

step 2: Then go to your admin panel and enable the Rewrites(set yes for Use Web Server Rewrites). You can find it at System->Configuration->Web->Search Engine Optimization.

step 3: Then go to Cache management page (system cache management ) and refresh your cache and refresh to check the site.

lost_in_magento
  • 703
  • 8
  • 22
Sankar Subburaj
  • 4,992
  • 12
  • 48
  • 79
9

You have to enable mod_rewrite in apache to make clean urls to work

if mod_rewrite is not in phpinfo you have to install it by

sudo a2enmod rewrite
sudo apache2ctl -l

You need to replace the occurrence of AllowOverride none to AllowOverride all ( in /etc/apache2/sites-enabled/000-default)

Restart Apache

sudo service apache2 restart

In Magento’s admin go to System > Configuration > Web > search engine Optimization and change “Use Web Server Rewrites” to Yes

Akhilraj N S
  • 9,049
  • 5
  • 36
  • 42
  • For future readers: my issue stemmed from the default "AllowOverride" being set to `None` - it should be set to `All` (for least troublesome experience). – Jesse Jun 23 '14 at 22:33
  • 1
    This solved my problem, with the default .htaccess config – ilhnctn Nov 06 '17 at 09:23
7

How about this in your .htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
ErJab
  • 6,056
  • 10
  • 42
  • 54
  • 1
    No change at all. Magento stores its access at `var/.htaccess` though — would this be a problem? – delwin May 08 '12 at 18:10
  • 1
    Magento stores **one** of its htaccess files in var/.htaccess, there are several in its directory trees to prevent remote compromise or reading privileged locations. You should have one in your server root directory. – Fiasco Labs Sep 24 '13 at 00:22
2

Hi I'm late to the party.. just wanted to point out that the instructions from http://davidtsadler.com/archives/2012/06/03/how-to-install-magento-on-ubuntu/ were really useful.

I had Ubuntu server installed with Apache, MySql and Php so I thought I could jump to the heading Creating the directory from which Magento will be served from and I reached the same problem as the OP, i.e. I had 'index.php' needed in all the URLs (or I would get 404 not found). I then went back to Installing and configuring the Apache HTTP server and after restarting apache it works perfectly.

For reference, I was missing:

sudo bash -c "cat >> /etc/apache2/conf.d/servername.conf <<EOF
ServerName localhost
EOF"

... and

sudo a2enmod rewrite
sudo service apache2 restart

Hope this helps

Jonno
  • 1,976
  • 2
  • 21
  • 21
2

If the other solutions don't work for you, try this:

Step 1: (if your installation is in webroot)

Replace

    #RewriteBase /magento/

with

    RewriteBase /

Step 2:

Add following lines (inclusive exclude admin because backend needs index.php internally)

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.com/$1 [R=301,L]
RewriteRule ^index.php/(admin|user)($|/) - [L]
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]

right after

RewriteRule .* index.php [L] 

This works for me

In case it is still not working, double check Magento configuration: System->Configuration->Web->Search Engine Optimization. Rewrites must be enabled.

Stefan
  • 8,456
  • 3
  • 29
  • 38
1

I tried everything on the post but nothing had worked. I then changed the .htaccess snippet that ErJab put up to read:

RewriteRule ^(.*)$ 'folder_name'/index.php/$1 [L]

The above line fixed it for me. where *folder_name* is the magento root folder.

Hope this helps!

nanyaks
  • 171
  • 1
  • 7
1

Mainly If you are using Linux Based system Like 'Ubuntu' and this is only suggested for localhost user not for the server.

Follow all the steps mentioned in the previous answers. +

Check in Apache configuration for it. (AllowOverride All) If AllowOverride value is none then change it to All and restart apache again.

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Let me know if this step help anyone. As it can save you time if you find it earlier.

enter image description here

I am adding the exact lines from my htaccess file in localhost. for your reference

Around line number 110

<IfModule mod_rewrite.c>

############################################
## enable rewrites

Options +FollowSymLinks
RewriteEngine on

############################################
## you can put here your magento root folder
## path relative to web root

#RewriteBase /

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Images are for some user who understand easily from image the from the text:

enter image description here