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

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

Stack Overflow用户
提问于 2012-04-16 22:14:17
回答 4查看 16.9K关注 0票数 11

我需要从http://example.com/重定向到http://example.com/index.php

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-16 22:16:20

使用以下命令:

代码语言:javascript
复制
DirectoryIndex index.php
票数 20
EN

Stack Overflow用户

发布于 2012-04-16 22:16:33

试试这个:

代码语言:javascript
复制
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
票数 4
EN

Stack Overflow用户

发布于 2018-08-13 23:15:53

为了添加我自己的解决方案,由于the answer of Michael不适用于我,我做了如下操作:

代码语言:javascript
复制
RewriteEngine on

# These two lines redirect non-www to www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) https://www.example.com$1 [R=301,L]

# These two lines redirect the root to index.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]

这还会保留任何可能的现有查询字符串参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10175804

复制
相关文章

相似问题

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