如何在Apache httpd.conf中进行配置,将同一文件夹中的不同主页文件伪装成不同文件夹中的文件?

如何在Apache httpd.conf中进行配置,将同一文件夹中的不同主页文件伪装成不同文件夹中的文件?,apache,config,virtual,Apache,Config,Virtual,我有一个项目,其文件夹结构如下: /www /img /css /js /templates index1.html index2.html index3.html 如上所述,我有三个主页文件。因为它们有很多公共部分,所以它们位于一个项目文件夹中。所以事实上,它们属于一个项目。但我希望人们使用以下URL访问此网站: http://www.servername.com/project1/ http://www.servername.com/

我有一个项目,其文件夹结构如下:

/www
    /img
    /css
    /js
    /templates
    index1.html
    index2.html
    index3.html
如上所述,我有三个主页文件。因为它们有很多公共部分,所以它们位于一个项目文件夹中。所以事实上,它们属于一个项目。但我希望人们使用以下URL访问此网站:

http://www.servername.com/project1/
http://www.servername.com/project2/
http://www.servername.com/project3/
好像他们是三个不同的项目。因为我不想让人们知道这只是一个项目。我想让它们看起来像在三个不同的项目中,并且三个主页文件具有相同的名称(index.html)

因此,我必须在
httpd.conf
文件中配置虚拟目录。我将三个
节点放在
httpd.conf
文件中,但它似乎不起作用:

<IfModule dir_module>
    DirectoryIndex index1.html

    Alias /project1/ "E:/www/"
    <Directory "E:/www/">
        ......
    </Directory>
</IfModule>

<IfModule dir_module>
    DirectoryIndex index2.html

    Alias /project2/ "E:/www/"
    <Directory "E:/www/">
        ......
    </Directory>
</IfModule>

<IfModule dir_module>
    DirectoryIndex index3.html

    Alias /project3/ "E:/www/"
    <Directory "E:/www/">
        ......
    </Directory>
</IfModule>

DirectoryIndex1.html
别名/project1/“E:/www/”
......
目录索引index2.html
别名/project2/“E:/www/”
......
目录索引index3.html
别名/project3/“E:/www/”
......
那我该怎么做才能达到这个目的呢

您可以将其与重写和LocationMatch指令结合使用,以实现所有的功能。 但是,您使用的“伪装”一词让我觉得您真的需要阅读.htaccess手册:

模块别名

您可以将其与重写和LocationMatch指令结合使用,以实现所有的功能。 但是,您使用的“伪装”一词让我觉得您真的需要阅读.htaccess手册:


最好的可能是配置单独的主机名,实际上,所以
project1.example.com
project2.example.com
等等。您可以在http服务器配置中将它们配置为虚拟主机。除此之外,您唯一需要的是a记录的“通配符DNS解析”

但如果您真的想使用路径进行分离,那么最简单的方法是在文件系统中使用符号链接,这将允许对这些路径进行单独的配置。由于看起来您是在MS Windows上,所以您没有该选项,该系统不提供此类功能。所以你必须试着解决这个问题

因为每个文件夹只能有一个
DirectoryIndex
指令,所以您的方法不起作用。但是,既然您的“项目”显然只包含一个静态html文件,为什么不简单地相应地更改
Alias
指令呢

Alias /project1 "E:/www/index1.html"
Alias /project2 "E:/www/index2.html"
Alias /project3 "E:/www/index3.html"
DocumentRoot "E:/www"
<Directory "E:/www/">
    # Whatever options you need for the common folder
</Directory>
Alias/project1“E:/www/index1.html”
Alias/project2“E:/www/index2.html”
Alias/project3“E:/www/index3.html”
DocumentRoot“E:/www”
#公用文件夹所需的任何选项

另一种方法是使用“内部重写”。显然,您需要加载并激活重写模块(mod_rewrite)。然后你可以这样做:

RewriteEngine on
RewriteRule ^/?project1 /index1.html [END]
RewriteRule ^/?project2 /index2.html [END]
RewriteRule ^/?project3 /index3.html [END]
DocumentRoot "E:/www"
<Directory "E:/www/">
    # Whatever options you need for the common folder
</Directory>
重新编写引擎打开
重写规则^/?project1/index1.html[结束]
重写规则^/?project2/index2.html[结束]
重写规则^/?project3/index3.html[结束]
DocumentRoot“E:/www”
#公用文件夹所需的任何选项
这可能会导致加载css文件等资产时出现问题。这取决于网站内部引用的结构

注意:如果遇到http状态500(“内部服务器错误”),请查阅http服务器错误日志文件以查找特定问题。很可能您操作的是非常旧版本的apache http服务器,
[END]
标志不可用。在这种情况下,请尝试改用
[L]
标志


重写模块提供了比别名模块更大的灵活性,但也增加了复杂性

实际上,最好是配置单独的主机名,所以
project1.example.com
project2.example.com
等等。您可以在http服务器配置中将它们配置为虚拟主机。除此之外,您唯一需要的是a记录的“通配符DNS解析”

但如果您真的想使用路径进行分离,那么最简单的方法是在文件系统中使用符号链接,这将允许对这些路径进行单独的配置。由于看起来您是在MS Windows上,所以您没有该选项,该系统不提供此类功能。所以你必须试着解决这个问题

因为每个文件夹只能有一个
DirectoryIndex
指令,所以您的方法不起作用。但是,既然您的“项目”显然只包含一个静态html文件,为什么不简单地相应地更改
Alias
指令呢

Alias /project1 "E:/www/index1.html"
Alias /project2 "E:/www/index2.html"
Alias /project3 "E:/www/index3.html"
DocumentRoot "E:/www"
<Directory "E:/www/">
    # Whatever options you need for the common folder
</Directory>
Alias/project1“E:/www/index1.html”
Alias/project2“E:/www/index2.html”
Alias/project3“E:/www/index3.html”
DocumentRoot“E:/www”
#公用文件夹所需的任何选项

另一种方法是使用“内部重写”。显然,您需要加载并激活重写模块(mod_rewrite)。然后你可以这样做:

RewriteEngine on
RewriteRule ^/?project1 /index1.html [END]
RewriteRule ^/?project2 /index2.html [END]
RewriteRule ^/?project3 /index3.html [END]
DocumentRoot "E:/www"
<Directory "E:/www/">
    # Whatever options you need for the common folder
</Directory>
重新编写引擎打开
重写规则^/?project1/index1.html[结束]
重写规则^/?project2/index2.html[结束]
重写规则^/?project3/index3.html[结束]
DocumentRoot“E:/www”
#公用文件夹所需的任何选项
这可能会导致加载css文件等资产时出现问题。这取决于网站内部引用的结构

注意:如果遇到http状态500(“内部服务器错误”),请查阅http服务器错误日志文件以查找特定问题。很可能您操作的是非常旧版本的apache http服务器,
[END]
标志不可用。在这种情况下,请尝试改用
[L]
标志


重写模块提供了比别名模块更大的灵活性,但也增加了复杂性

谢谢大家!!但是我不能修改主机名,它是固定的。我只能修改d