26

I am using Magento ver. 1.7.0.2.

Here it is the link to my website: http://dev.blokeundees.com.au/

I have to remove the /index.php folder from URLs so I edited the .htaccess file and backend too (secure, web server rewrites) and /index.php has been properly removed.

But when accessing the frontend, it returns a 404 error (Page not found) for every page except the index page.

I don't know why this is happening.

13 Answers 13

26

How to Remove index.php from Magento URLs

Magento is a fantastic platform for selling online, arguably the best, but there’s one thing that has always left me frustrated as an SEO… That pesky index.php directory in the URL of ALL internal pages – nightmare!

There’s no benefit to them.

They’re bad for SEO, bad for site structure and consistency, and then they’re even worse for a clean URL freak like me. They’re not sexy enough. Let’s clean things up.

SEO Friendly Magento URLs in Two Steps

Fortunately, whilst I was doing a Magento store for a client recently, I did a little bit of digging and found a pretty straightforward solution to the issue. It involves a couple of changes to the Magento admin settings and the addition, or modification, of a simple .htaccess file to sort out of the rewriting of their standard store URLs.

Follow the simple steps below and you’ll be a step closer to SEO success with your own Magento store, and your SEO won’t have an excuse for decreased relevancy.

1) Let’s Change a Setting, Admin

The first thing you need to do is to login to your Magento admin panel (index.php/admin) in order to change a very simple setting which will let Magento know that you intend to use URL rewriting throughout your store rather than their ugly default URLs.

Login, and change this setting:

Go to System > Configuration > Web > Search Engine Optimization

Use Web Server Rewrites: YES

That was easy, wasn’t it? Okay, now for the final step.

2) Let’s Use a .htaccess File to Rewrite the URLs

The final step involves creating a .htaccess file in the Magento installation folder in order to compliment the settings you changed within your admin settings earlier, and this will actually rewrite the URLs. Choose the applicable .htaccess version below.

If your Magento store is installed in root (public_html), use this:

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

If your Magento store is installed in a subfolder (public_html/shop), use this:

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

You’re done – hope that helps!

It’ll definitely stop your SEO from pulling out his or her hair.

Let me know in the comments below if you use this or run into any issues!

  • 1
    This doesn't work in my version of Magento, 1.9.x. It removes the index.php from the url, but results in 404s left and right. – Summer Developer Jan 10 '17 at 2:10
10

Make sure you have a working .htaccess file, optionally you can take it from a fresh Magento version download.

Also check if mod_rewrite is enabled on your server. That can be done by reading the phpinfo(); from a script on your server. This Stackoverflow post tells you how.

  • Also you need to be sure that System -> Configuration -> Web -> Search Engines Configuration -> Use Web Server Rewrites is enable. – Barbanet May 19 '14 at 23:20
  • Working & writable .htaccess file. – Raptor Oct 13 '14 at 6:17
6

To remove index.php from URLs follow the below steps :

  1. Log-in Magento Admin
  2. Go to System -> Configuration -> Web
  3. From Search Engine Optimisation tab Use Web Server Rewrites select YES.
  4. Make sure your Secure and Unsecure base urls should end with “/”.
  5. Now edit your .htaccess ( will be in magento root folder ) and paste the code which is given at this link
5

You does not need to change other than following points . just do these two settings and you will be ok . in System -> Configuration -> Web -> Search Engines Optimizations, select YES.

And in System -> Configuration -> Web -> Secure -> Use secure URLs in the frontend, select YES. Refresh your cache if still facing issue do following in your httpd.config file . AllowOverride None change to AllowOverride All All will be OK now

  • In my httpd.config, there is no line like, AllowOverride None ,. then how can i change AllowOverride All – zus Apr 6 '18 at 6:22
3

Mostly, when we work in WAMP/XAMPP, we need:

1) to check rewrite_module has been enabled

for example, when we install wampp in C:\wamp, we can find the httpd.conf in C:\wamp\bin\apache\apache2.4.9\conf and enable it by remove # sign to be

LoadModule rewrite_module modules/mod_rewrite.so

2) to enable RewriteBase

for example, when we install magento v1.9 in C:\wamp\www\magento, we need to edit the default .htaccess in magento root folder to be

RewriteBase /magento/

And also, we need to enable the default rewrite rule by removing the # sign

RewriteRule .* index.php [L]

3) in System -> Configuration -> Web -> Search Engines Optimizations, select YES.

And in System -> Configuration -> Web -> Secure -> Use secure URLs in the frontend, select YES.

When we work in LAMP server, it is similar that we need to check all above items to enable the rewrite module to work, thought there should many details differences.

3

Working solution to remove index.php from URL excluding Admin.And if anyone place index.php in URL it will redirect to URL which doesn't contains index.php. For this we also need to set,Use Web Server Rewrites - Yes from Search Engines Optimization

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/index.php/admin/
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]
3

First go to system->configuration->web->Search Engines Optimization

And select yes in Use Web Server Rewrites dropdown

Now Go to your site root

Open .htaccess file if not then create .htaccess file

in local this file is hidden so you need to show hidden files (ctrl+H)

Now if your root in public_html/ then copy this code into .htaccess

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

If your Site is in a subfolder public_html/yoursite Copy this code in .htaccess

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

Make sure mod_rewrite is enabled on your server. In my case it was disabled. Once i enabled it in server, it is working properly.

  • How can i check myself if mod_rewrite enabled or not in my server, – zus Apr 6 '18 at 6:25
2
  1. Goto your site root folder and you can find the .htaccess file. Just edit that. Open it on a text editor and find this line,

Rewrite Base /magento/ .

Just replace it with

Rewrite Base / . Put the following code in the .htaccess

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

In case your Magento is installed in sub-folder, e.g. ‘shop’, you should use the following code:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /shop/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /shop/index.php [L] </IfModule>
  1. Then goto your Admin Panel and enable the Web Server Rewrites. You can find it at System > Configuration > Web > Search Engine Optimization.

Now set the “Use Web Server Rewrites” option under “Search Engines Optiomization” to “Yes”.

  1. Then, set the “Use Secure URLs in Frontend” option under “Secure” to “Yes”. Click “Save Config” button in the top right:

  2. Then goto your Cache Management page ( System > Cache Management) and refresh your Cache and also refresh the Web Redirects.

2

I just had to change following text in .htaccess file at root of magento project:

#RewriteBase /magento/

to

RewriteBase /magento/

Note: just change magento with your website name.

2

Remove index.php from URL including inner pages into Magento using the following steps:

Check admin panel: Use Web Server Rewrites' should be set to 'Yes' in Web > Search Engines Optimization and then follow given below 2 steps.

Step 1: --------------- Insert this code on top of all layout files (1column and all others) --------------

<?php 
$abc = Mage::helper('core/url')->getCurrentUrl();
if(strpos($abc,'index.php/') !== false) {
$pos = strpos($abc,'index.php/');
$p1 = substr($abc,0,$pos);
$p2 = substr($abc,$pos+10,strlen($abc));
$url = $p1.$p2;
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();
}
?>

--------------------------------- END Step 1 ---------------------------------------

Step 2 : --------------- Insert this code before 'Rewrite engion ON' into htaccess file --------------

index.php on default domain

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteRule ^(.*)index.php$ www.abc.com [R=301,L]
RewriteCond %{HTTP_HOST} ^abc.com$ [NC]

HTTP to HTTPS redirection

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

----------------------------------- END Step 2 -------------------------------------------------

Note: In step 2, just change the URL for your site. Don't need to do anything in step 1.

1

If anyone using Apache2 ubuntu 16.04 , you don't see httpd.conf file anywhere in server, so you need to go to path : /etc/apache2/apache2.conf , than replace below code

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

with below code :

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

After this, restart server : sudo service apache2 restart

0
  • Go to System > Configuration > Web > Search Engine Optimization > Use Web Server Rewrites select YES.
  • sudo a2enmod rewrite
  • service apache2 restart

These 3 worked for me.

protected by Community Mar 24 '16 at 1:27

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.