How to Remove Index.php from URL in Magento
From the below two URLs, which one would you consider more readable, SEO-friendly and user-friendly?
http://meetanshi.com/index.php/magento-extension
OR
http://meetanshi.com/magento-extension
Shorter, the better. Isn’t it?
According to Google, the site’s URL structure should be as simple as possible. Additionally, the URLs with a structured hierarchy are preferred by GoogleBot as it makes the crawling throughout the site easier.
However, the default Magento and Magento 2 offers URLs with a lingering “index.php” and it is recommended to remove it.
Other benefits of short and simple URLs are:
- Affects CTR. Users may examine the URL to decide whether to click or not.
- Improved anchor text link juice flow
- A minor ranking factor
Magento surely is the best platform for E-commerce stores but for the SEOs like me, the pesty index.php can be a nightmare!
So, here’s the method to remove index.php from URL in Magento!
Get simple and short URLs without index.php with these easy steps:
Note: This method only works if mod_rewrite is enabled. The configuration for Magento 2 is in accordance with the Magento 2.3.0 version.
Steps to Remove Index.php from URL in Magento:
For Magento 2:
- Log in to Admin panel
- Navigate to Stores > Configuration > General > Web
- Expand the Search Engine Optimization section
- Set “yes” to Use Web Server Rewrites option.
- Further, expand the Base URLs (Secure) section
- Set “yes” to Use Secure URLs on Storefront
- Save the configuration
For Magento 1,
- Log in to Admin Panel
- Navigate to System > Configuration > General > Web
- Expand the Search Engines Optimization section
- Set “yes” to Use Web Server Rewrites option.
- Expand the Secure tab
- Set “yes” to Use Secure URLs in Frontend
Follow the above steps for your Magento version.
Note: If you still have an issue in removing the index.php, use a .htaccess File to Rewrite the URLs
Create a .htaccess file in the Magento installation folder to compliment the configuration within your admin panel, 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:
1 2 3 4 5 6 |
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:
1 2 3 4 5 6 |
RewriteEngine On RewriteBase /shop/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /shop/index.php [L] |
For the programmatic method of URL Rewrite in Magento 2, check our blog post.
Hope it helps.
Please feel free to use the Comments section below if you have any doubts in the above method.
Thank you!
Shivbhadrasinh Gohil
Shivbhadrasinh is the Co-founder & Chief Marketing Officer at Meetanshi. He leads the marketing team and is the person behind the marketing & branding success of the company. Being a seasoned digital marketer, he has been consulting online businesses for growth since 2010 and has helped 100+ clients with digital marketing success.
He loves sharing tips and insights about the latest digital marketing trends aimed at helping online business owners.
4 Comments
Hi, every time I check weblog posts here in the early hours in the break of
day, because I love to gain more knowledge about Magento!
Thanks!
Hello, all is going sound here and ofcourse every one is sharing data, that’s genuinely
excellent, keep up writing.
Thanks!