代码之家  ›  专栏  ›  技术社区  ›  animuson

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

  •  1
  • animuson  · 技术社区  · 16 年前

    我的htaccess文件有点小问题。目前,它将所有内容重定向回index.php进行处理,除非有人试图访问实际目录。当目录存在时,它将显示403错误页,而不是像预期的那样将路径重写为index.php。当通过Internet访问文件时,我可以修改什么使其始终转到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目录文件夹中返回index.php文件,无论什么。

    1 回复  |  直到 16 年前
        1
  •  1
  •   Tim Stone    16 年前

    我想你应该改为:

    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。如果这些假设中的任何一个是错误的,请告诉我,我将用适当的重写信息更新答案。

    推荐文章