【问题标题】:htaccess wildcard subdirectoryhtaccess 通配符子目录
【发布时间】:2014-07-02 12:32:11
【问题描述】:

我需要设置一个 htaccess 文件来将不存在的子目录别名到一个公共位置。 URL 应该看起来好像目录确实存在。如果存在目录或文件,则应使用这些文件

RewriteEngine On

#Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule (.*)/(.*)/(.*) current/$2/$3 [QSA,L]
RewriteRule (.*)/(.*) current/$2 [QSA,L]

如何容纳第 N 个子目录?顶层是唯一需要别名的。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    斜线对于RewriteRule 并不特殊。只要确保你没有抓住第一个。

    RewriteRule ^/?([^/]*)/(.*)$ current/$2 [QSA,L]
    

    【讨论】:

    • 如果别名目录上没有尾部斜杠,是否可以将其更改为 for to current/index.php?
    • 我不会。只需为其添加另一个规则。
    猜你喜欢
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 2015-05-20
    • 2010-12-28
    • 2016-09-14
    • 2015-09-26
    • 2014-09-06
    • 1970-01-01
    相关资源
    最近更新 更多