我在我的共享主机服务器上安装了 Magento。我已经在 magento 管理面板中进行了所有必要的更改。所有网址都可以正常工作。但唯一的问题是我可以使用以下方式在商店中访问我的产品:
http://mydomain.com/category/product.html还有http://mydomain.com/index.php/category/product.html
所以我想知道如何摆脱 index.php。我想将包含 index.php 的 url 重定向到没有 index.php 的 url
在这里发帖之前,我查看了 magento 论坛并在 stackoverflow 上进行了搜索,但没有找到任何结果。
最佳答案
您可以捕获index.php
之后的部分并使用
RewriteEngine on
RewriteRule ^index\.php/(.+)$ /$1 [R,L]
RewriteRule ^index\.php/?$ / [R,L]
这会将所有以 index.php/
开头的请求重定向到没有 index.php
的 URL。另外 index.php
和 index.php/
被重定向到主页。
更新:
要排除管理区域,您必须插入额外的 RewriteCond
在第一条规则之前
RewriteCond %{REQUEST_URI} !/admin/
一起给
RewriteEngine on
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule ^index\.php/(.+)$ /$1 [R,L]
RewriteRule ^index\.php/?$ / [R,L]
关于.htaccess - 将 index.php 重定向到 .htaccess 中的根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15476019/