Remove index.php from URL in Magento 2

In this blog, we will discuss how to remove indx.php from URL in Magento 2.

First check if mod rewrite is enabled or not →

For that :-->

1. Create mod_rewrite.php in root




2. Write this code in .htaccess



RewriteEngine On

RewriteRule ^.*$ mod_rewrite.php

If the message show "Mod_rewrite is activated!" then mod_rewrite is enable

Then follow this steps below →

Add this in .htaccess →





RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

//Important section

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]



And next you can set url rewrite to yes in magento 2 admin --

You can direct change From db : → Core config data : → web/seo/use_rewrite value to 0

Admin : → store > configuration > general > web > use web server rewrites to Yes.

Else : →

1. sudo a2enmod rewrite //for mod rewrite enable

After that restart apache server

2. sudo systemctl restart apache2

3. Open this file :-->

/etc/apache2/sites-available/000-default.conf

Add this line after: ()





        Options Indexes FollowSymLinks MultiViews

        AllowOverride All

        Require all granted

    

4. sudo systemctl restart apache2



sudo nano /var/www/html/.htaccess

Add this line at the top of the new file to activate the rewrite engine:-->



/var/www/html/.htaccess

RewriteEngine on

Conclusion:

You can use the code in Magento development. Please share your review in the comment section.

Comments

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.