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

当使用apache mod_alias和mod_rewrite时,如何检测uri中的根文件夹?

  •  0
  • vdrmrt  · 技术社区  · 15 年前

    当使用apache mod_alias和mod_rewrite时,如何检测uri中的根文件夹?

    我在文档根目录的子文件夹上运行了一个网站,例如/var/www/this/an/other/dir。在这个文件夹中,我有一个带有mod重写规则的.ht_访问文件,可以将所有内容重定向到index.php。

    # Do nothing if the file (s), link (l) or (d) exists
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    
    # Redirect everything else to index.php
    RewriteRule ^.*$ index.php [E=PORT:%{SERVER_PORT},NC,L]`
    

    我还为方便访问设置了别名

    alias /foo /var/www/this/an/other/dir
    

    现在当我去地址的时候 http://host.com/foo/bar/ 如何检测/foo是我的uri的根文件夹?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Geoffrey Bachelet    15 年前

    SetEnv AliasRoot /foo
    

    $_ENV

    $root = $_ENV['AliasRoot'];
    

        2
  •  0
  •   Your Common Sense    15 年前


    /
    dirname($_SERVER["SCRIPT_FILENAME"])

    推荐文章