在处理目录之前重写路径?
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您想要这样:
这是假设您不希望能够直接访问
TEST.HTML
并且不希望更改用户浏览器中的 URL。如果这些假设中的任何一个是错误的,请告诉我,我将使用适当的重写信息更新答案。I think you want this instead:
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.