在处理目录之前重写路径?

发布于 2024-09-08 15:10:27 字数 678 浏览 0 评论 0原文

我的 htaccess 文件有一个小问题。目前,它将所有内容重定向回 index.php 进行处理,除非有人尝试访问实际目录。当目录存在时,它会显示 403 错误页面,而不是像预期的那样重写 index.php 的路径。我可以修改什么以使其在通过互联网访问文件时始终转到index.php,但仍然在服务器上的 PHP 中加载正确的文件?

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule !^(.*) index.php [L]

文件结构示例:

Web Directory
- com
- source
- index.php
- TEST.HTML

“com”和“source”等文件夹将显示 403,因为用户无权访问它们。 “index.php”和“TEST.HTML”等文件正常执行。无论如何,我希望我的 htaccess 将 Web Directory 文件夹中的所有内容重定向回index.php 文件。

I'm having a small problem with my htaccess files. Currently, it redirects everything back to index.php for processing, except when someone tries to access an actual directory. When the directory exists, it displays the 403 error page instead of rewriting the path to index.php like it's supposed too. What can I modify to make it always go to index.php when the files are accessed via the internet, but still load the correct files in PHP on the server?

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule !^(.*) index.php [L]

Sample file structure:

Web Directory
- com
- source
- index.php
- TEST.HTML

The folders such as 'com' and source' will display the 403 because the user doesn't have access to them. The files such as 'index.php' and 'TEST.HTML' execute normally. I want my htaccess to redirect everything in the Web Directory folder back to the index.php file, no matter what.

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

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

发布评论

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

评论(1

归属感 2024-09-15 15:10:27

我认为您想要这样:

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* index.php [L]

这是假设您不希望能够直接访问 TEST.HTML 并且不希望更改用户浏览器中的 URL。如果这些假设中的任何一个是错误的,请告诉我,我将使用适当的重写信息更新答案。

I think you want this instead:

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 403 /index.php?403
ErrorDocument 404 /index.php?404
ErrorDocument 414 /index.php?414

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* index.php [L]

This was on the assumption that you didn't want to be able to access TEST.HTML directly and didn't want to change the URL in the user's browser. If either of those assumptions were wrong, let me know and I'll update the answer with the appropriate rewrite information.

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