【问题标题】:Route user to some file like: index.php from any folder which is not having index.php | using .htaccess将用户路由到某个文件,例如:从任何没有 index.php 的文件夹中的 index.php |使用 .htaccess
【发布时间】:2013-07-04 12:38:38
【问题描述】:

我的.htaccess 文件中有此代码,用于将用户路由到我的root/index.php 文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

但是,这很好用:所以如果我要去 localhost/MyFolder/Xyz 并且如果 Xyz is not existing it takes me to localhost/index.php 现在我想要的是,我有像 css js images 这样的文件夹,所以我没有任何 @ 987654329@ 文件在那里,所以它列出了我所有的文件。我知道我可以在那里添加 index.php 文件,并且可以将用户重定向到我的根目录。但这是一项 TDS 工作。有什么方法可以让我在.htaccess 和任何文件夹中做某事,如果它无法找到index.php,它会将我带到localhostindex.php

有办法吗。只是不想将index.php 放在每个文件夹中以限制其访问。

【问题讨论】:

    标签: php linux apache .htaccess web


    【解决方案1】:

    您基本上想要的是避免在没有索引文件时列出文件夹的所有文件。

    您可以通过将其添加到您的 .htaccess 文件中来实现此目的:

    Options All -Indexes
    

    【讨论】:

    • 好的,这个东西不显示我目录的文件。现在有什么方法可以将用户重定向到link??
    • 同样在这样做之后它不会显示子目录但它给了我错误 500。这是我不想要的。因此,如果我可以将用户重定向到link,那将是必要的。谢谢
    【解决方案2】:

    好的,我认为您想要的只是从您的 .htaccess 文件中删除重写条件。如果输入的路径是文件或目录的路径,这些重写条件告诉 Apache 不要重定向。

    RewriteEngine On
    
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
    

    就是这样。

    【讨论】:

      猜你喜欢
      • 2016-02-11
      • 2020-11-05
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多