Stop ability to load site as both example.com and example.com/index.php
-
08-02-2021 - |
Question
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
La solution
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/
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange