【问题标题】:Is there a way to redirect one directory as a root and its siblings as sub directories only via Apache2.4 mod_rewrite?有没有办法仅通过 Apache2.4 mod_rewrite 将一个目录重定向为根目录,并将其兄弟目录重定向为子目录?
【发布时间】:2020-12-20 09:49:51
【问题描述】:

我必须配置一个 HTTPD 服务器以从多个子目录之一为主站点提供服务,而将所有其他的都解析为站点子目录。为了更清楚,假设我的根目录如下所示:

/var/www/
˫module_1
˫module_2
˫module_3
˫html

我想要的网址是:

example.com/module1 -> gets data from module_1 directory
example.com/module2 -> gets data from module_2 directory
example.com/module3 -> gets data from module_3 directory
example.com/ -> gets data from html directory

我尝试了一些来自网络的解决方案,但结果是错误的,比如将所有内容重定向到 html 或尝试在 html 中查找 module 数据> 文件夹。

【问题讨论】:

    标签: apache http web redirect mod-rewrite


    【解决方案1】:

    您可以尝试以下代码作为参考:

    <VirtualHost *:80>
    
    ServerName example.com
    
    DocumentRoot /var/www/
    <Directory "/var/www/">  
    Options +Indexes  
    AllowOverride None  
    Order allow,deny  
    Allow from all  
    </Directory>
    
    </VirtualHost>
    

    【讨论】:

    • 感谢您的回复,但我可能需要重构这个应用程序,因为它会在未来引起很多问题。并且Options +Indexes 可能会导致向用户显示我的文件结构并且我觉得很危险。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2019-07-20
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多