Magento – Changes in root .htaccess file not reflecting in Magento 2

.htaccessmagento-2.1url-rewrite

I am using Magento 2.1.

I am trying to add a rewrite rule in .htaccess file for url's starting with index.php?route=. to be replaced with the query string.

RewriteCond %{QUERY_STRING} ^index.php?route=.+$ [NC]
RewriteRule ^(.*)$ /%{QUERY_STRING}\? [R=301,L]

But this url rewrite rule is not getting reflected in my site.

Am I editing the right file(root/.htaccess).?

Please suggest a solution to my problem.

Best Answer

Check if mod_rewrite is enabled on your server. That can be done by reading the phpinfo(); from a script on your server.

Use the below code in .htaccss

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

Other way is

  1. Log-in Magento Admin
  2. Go to Stores-> 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 “/”.

Remove cache and check.

Related Topic