Domanda

I've just noticed that I can load pages within and without index.php in the URL.

So, I can load these URLs:

  • example.com
  • example.com/index.php (I don't want this)
  • example.com/product.html
  • example.com/index.php/product.html (I don't want this)

I'm running M2+Apache, and would like to know how to stop this from happening.digital

È stato utile?

Soluzione

You can remove all the index.php's from your frontend URLs, by adding the following rewrite rules to your apache config (.htaccess):

RewriteEngine on
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule ^index\.php/(.+)$ /$1 [R,L]
RewriteRule ^index\.php/?$ / [R,L]

1st line: turns on rewrite engine

2nd line: makes sure to leave index.php alone for all admin URLs

3rd line: removes index.php from the URL and redirects to that version ex. example.com/index.php/product.html becomes example.com/product.html

4th line: handles redirecting example.com/index.php to example.com/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top