简体   繁体   English

Apache2 httpd.conf帮助

[英]Apache2 httpd.conf help

I have a domain, for example, http://example.com . 我有一个域,例如http://example.com It is already configured to point to 它已经配置为指向

/var/www/

Basically, i want http://example.com to point to 基本上,我希望http://example.com指向

/var/www/4.0/

and http://example.com/foobar/ to point to http://example.com/foobar/指向

/var/www/moo/

How can I do this with the httpd.conf file for Apache2? 如何使用Apache2的httpd.conf文件执行此操作? Thanks 谢谢

Assuming you are only serving one domain (example.com), you can change your DocumentRoot to /var/www/4.0/ 假设您只提供一个域(example.com),则可以将DocumentRoot更改为/var/www/4.0/

and set an Alias for the /foobar like 并为/foobar设置Alias

Alias /foobar /var/www/moo

If you are serving more than one domain from the same Apache, then you need to use the DocumentRoot within a VirtualHost tag. 如果要从同一Apache提供多个域,则需要在VirtualHost标记中使用DocumentRoot。

More info is here: http://httpd.apache.org/docs/2.2/vhosts/ 更多信息在这里: http : //httpd.apache.org/docs/2.2/vhosts/

I think you're going about this the wrong way with httpd.conf, but I'll answer your question as you asked it first and then explain about that. 我认为您使用httpd.conf的方式是错误的,但是我将按照您首先提出的问题回答您的问题,然后对此进行解释。

There are two settings in httpd.conf relevant to this. httpd.conf中有两个与此相关的设置。 The DocumentRoot setting is the important one, it configures the base directory from which to serve. DocumentRoot设置是重要的设置,它配置要服务的基本目录。 Change it as so: 如此更改:

Before:
DocumentRoot "/var/www"

After:
DocumentRoot "/var/www/4.0"

Be sure not to use any / after the 4.0, it's not needed. 确保在4.0之后不要使用任何/,这是不必要的。 A little under 30 lines below this setting is another, which should say: As the comment above it says, change it to "/var/www/4.0" too. 低于此设置的30行以下是另一行,应该说:如上面的注释所述,也将其更改为“ /var/www/4.0”。 This would set www.example.com to the 4.0 directory (first part) and apply the relevant settings to this directory too (second part). 这会将www.example.com设置为4.0目录(第一部分),并将相关设置也应用到该目录(第二部分)。

But I don't think you should do that, setting apache to serve the 4.0/ directory with httpd.conf makes a mess for serving the other directories. 但是我不认为您应该这样做,将apache设置为使用httpd.conf服务4.0 /目录会使服务其他目录变得一团糟。 I'd suggest you read about redirects and how to implement them with whatever language you're using. 我建议您阅读有关重定向以及如何使用所使用的任何语言实现重定向的信息。 Then you can point one URL to another without it ever being noticed in the browser (unless they're really trying to). 然后,您可以将一个URL指向另一个URL,而不必在浏览器中注意到它(除非它们确实在尝试这样做)。

So without changing DocumentRoot from "/var/www", you can edit /var/www/index.php (or whatever) and have it redirect to /var/www/4.0/. 因此,无需从“ / var / www”更改DocumentRoot,就可以编辑/var/www/index.php(或其他任何文件)并将其重定向到/var/www/4.0/。 The same can be done in /var/www/foobar/index.php to display /var/www/moo/ instead, but here I'd really just rename the "foobar" directory on the server to "moo". 可以在/var/www/foobar/index.php中执行同样的操作以显示/ var / www / moo /,但是实际上,我只是将服务器上的“ foobar”目录重命名为“ moo”。 If you want to get elaborate, look into mod_rewrite, but I'd advise you to try all your alternatives first and only use it if you really need to, it's quite a complex tool. 如果要详细说明,请查看mod_rewrite,但我建议您首先尝试所有替代方法,并且仅在确实需要时使用它,这是一个非常复杂的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM