.htaccess 中的索引文件

发布于 2024-09-17 18:50:47 字数 620 浏览 1 评论 0原文

在我的 htaccess 文件中,我有以下重定向:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule index.html$ Controller/index.php [L]
</IfModule>

我希望将 index.html (不存在)重定向到我的控制器。 index.php(存在)应该是我的主页。

现在,在浏览器中输入 http://www.domain.com/ 时,我的主页无法正常工作。该 URL 重定向到我的控制器。 http://www.domain.com/index.php 工作正常,带来了我的主页。

如何将 index.php 设置为索引文件以保持控制器的重定向?

In my htaccess file I have the following redirections:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule index.html$ Controller/index.php [L]
</IfModule>

I want index.html (which does not exist) to be redirected to my controller.
index.php (which exists) should be my home page.

Now, my homepage is not working when typing http://www.domain.com/ in my browser. That URL redirects to my controller.
http://www.domain.com/index.php works fine, bringing my homepage.

How do I set index.php as my index file keeping my redirection for the controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光与爱终年不遇 2024-09-24 18:50:47

如果我正确理解了您的情况,您只需指定 DirectoryIndex 在您的 .htaccess 文件中,以便它仅指向 index.php

DirectoryIndex index.php

在该规则和您的规则之间,会导致以下结果URL 到文件的映射:

http://www.example.com/           -> /index.php
http://www.example.com/index.php  -> /index.php
http://www.example.com/index.html -> /Controller/index.php

If I've understood your situation correctly, you just want to specify DirectoryIndex in your .htaccess file so that it only points to index.php:

DirectoryIndex index.php

Between that and your rules, that leads to the following URL to file mappings:

http://www.example.com/           -> /index.php
http://www.example.com/index.php  -> /index.php
http://www.example.com/index.html -> /Controller/index.php
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文