Link to home
Start Free TrialLog in
Avatar of chrismarx
chrismarxFlag for United States of America

asked on

Redirect just the root location of virtual host

I have a virtual host

 x.y.z.edu

and i have many sites that use it

x.y.z.edu/1/
x.y.z.edu/2/

but i need to redirect request for

x.y.z.edu/

to another site. How do i do this in the apache httpd.conf?
thanks!
Avatar of Ghoti_AZ
Ghoti_AZ

Looks like you want to use a 301 Redirect with IIS:

In internet services manager, right click on the file or folder you wish to redirect.
Select the radio titled "a redirection to a URL".
Enter the page that the page will be redirected to.
Check "The exact url entered above" and the "A permanent redirection for this resource".
Click on 'Apply'.

The subdirectories should still be accessible normally.
Avatar of chrismarx

ASKER

hmm, i posted this under apache, maybe its showing up in a different category, but I need to do this for apache server (by editing http.conf file)
with

  RedirectMatch 301 ^/$ http://othersite/

inside of your <virtualhost> for  x.y.z.edu
Apologies, somehow I got my apples and oranges in the wrong cart.  Indeed, you still want a 301 redirect.

Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.

Here is how to do it:

Create a file on the root directory of your website, name it ".htaccess".
Open the .htaccess file using nano, vim, or what ever text editor that you prefer.
Add the code snippet into the .htaccess file.

NOTE:  The '/' in the snippet is the path (in the context of a browser's address bar) to the original URL. As you are redirecting from the root, that is the location indicated by '/'.

Redirect 301 / http://www.example.com/path/to/new/location.html

Open in new window

so the $ means just the root?

and what do you instead of virtualhost, i still want to keep that...

i have something like this

# 199.999.999.99
<VirtualHost 199.999.999.99:80>
    DocumentRoot /web/www/x.y.z.edu
    ServerName x.y.z.edu

    ### ERRORS ###
    ErrorDocument 404 /not_found
    ErrorDocument 500 /status/
    ErrorDocument 502 /badgateway/index.html
    ErrorDocument 503 /badgateway/index.html

can i just add your

RedirectMatch 301 ^/$ http://othersite/

why do i need the 301?
The 301 is an HTTP error code used to redirect a browser to a new (or, in your case, correct) location of a web site.  When a client goes to your page, your server will send a 301 with the new URL, and the browser will transparently just go to the correct location.  Caster and I just gave two methods to accomplish the 301 redirect is all; the .htaccess method that I posted, I thought, would be less intrusive to the other sites you alluded to in your original post.
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks!!