.htaccess - 将 index.php 重定向到 .htaccess 中的根目录

标签 .htaccess magento mod-rewrite url-rewriting magento-1.7

我在我的共享主机服务器上安装了 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.phpindex.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/

相关文章:

apache - .htaccess 多语言网站

azure - Azure 上的静态网站使用 htaccess 文件强制使用 https

nginx - Nginx 中的多站点 WordPress 重写规则

php - 使用 mod_rewrite 指示伪目录的文件名

php - 从 Magento 的产品集中获取产品媒体库图像

php - mod_rewrite 和带空格的超链接

javascript - htaccess 实现后阻塞的框架

html - https 和 http 重定向

Magento - 如何清理不在属性集中的属性

css - Magento 中的下拉菜单悬挂得太低并在嘴巴移动时消失