发布于 2025-01-25 05:18:01 字数 665 浏览 2 评论 0原文

我在.htaccess中对某些规则有疑问。

我想将所有网页放在/pages/文件夹中,包括index.php

因此,这是我在.htaccess中的规则:

#root / to pages/index.php
RewriteRule ^$ /pages/index.php [L,QSA]

# if url is /index.php redirect /
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php$ / [R=301,L]

# if url is pages/index.php redirect /
RewriteCond %{THE_REQUEST} pages/index\.php
RewriteRule ^pages/index\.php$ / [R=301,L]

# if url is pages/ redirect /
RewriteCond %{THE_REQUEST} pages/
RewriteRule ^pages/$ / [R=301,L]

但是我的问题是... index.php ..有4个规则。我有疑问,

这似乎有效,但是我们可以简化它吗?

I have a question about some rules in .htaccess.

I want to put all my web pages in the /pages/ folder, including index.php.

So to do this, here are my rules in .htaccess:

#root / to pages/index.php
RewriteRule ^$ /pages/index.php [L,QSA]

# if url is /index.php redirect /
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php$ / [R=301,L]

# if url is pages/index.php redirect /
RewriteCond %{THE_REQUEST} pages/index\.php
RewriteRule ^pages/index\.php$ / [R=301,L]

# if url is pages/ redirect /
RewriteCond %{THE_REQUEST} pages/
RewriteRule ^pages/$ / [R=301,L]

But my question is... There are 4 rules for index.php.. so are the rules good? I have small doubts

It seems to work but can we simplify it?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文