简体   繁体   中英

Apache2 httpd.conf help

I have a domain, for example, http://example.com . It is already configured to point to

/var/www/

Basically, i want http://example.com to point to

/var/www/4.0/

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

/var/www/moo/

How can I do this with the httpd.conf file for Apache2? Thanks

Assuming you are only serving one domain (example.com), you can change your DocumentRoot to /var/www/4.0/

and set an Alias for the /foobar like

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.

More info is here: 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.

There are two settings in httpd.conf relevant to this. The DocumentRoot setting is the important one, it configures the base directory from which to serve. 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. 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. This would set www.example.com to the 4.0 directory (first part) and apply the relevant settings to this directory too (second part).

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. 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).

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/. 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". 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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