首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在.htaccess中将index.php重定向到根目录

问在.htaccess中将index.php重定向到根目录
EN

Stack Overflow用户
提问于 2013-03-18 19:44:39
回答 3查看 14.4K关注 0票数 2

我在我的共享主机服务器上安装了Magento。我已经在magento管理面板中做了所有必要的更改。所有的url都能正常工作。但唯一的问题是,我可以使用以下命令访问商店中的产品:

http://mydomain.com/category/product.html和http://mydomain.com/index.php/category/product.html

所以我想知道怎么才能摆脱index.php我想将包含index.php的url重定向到没有index.php的url

在这里发帖之前,我检查了magento论坛,也在stackoverflow上搜索,但没有找到成功。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-18 21:37:23

您可以捕获index.php之后的部分,并使用以下命令重定向客户端

代码语言:javascript
复制
RewriteEngine on
RewriteRule ^index\.php/(.+)$ /$1 [R,L]
RewriteRule ^index\.php/?$ / [R,L]

这会将所有以index.php/开头的请求重定向到不带index.php的URL。此外,index.php和index.php/被重定向到主页。

更新

要排除管理区域,必须在第一个规则之前插入额外的RewriteCond

代码语言:javascript
复制
RewriteCond %{REQUEST_URI} !/admin/

所有这些都会给出

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule ^index\.php/(.+)$ /$1 [R,L]
RewriteRule ^index\.php/?$ / [R,L]
票数 7
EN

Stack Overflow用户

发布于 2013-11-16 05:48:12

如果你想从你网站上的所有链接中删除index.php,这个解决方案对我来说是最好的:

代码语言:javascript
复制
RedirectMatch 301 /index.php/(.*) http://www.yourdomain.com/$1

来源:http://www.lionseo.com/blog/htaccess-redirect-301/

票数 4
EN

Stack Overflow用户

发布于 2018-05-15 19:14:43

使用此选项,您可以转义管理URL,并将301 index.php重定向到没有index.php url的位置

代码语言:javascript
复制
RedirectMatch 301 /index.php/((?!admin).*)$1 http://www.example.com/$1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15476019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档