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!
chrismarxAsked:
Who is Participating?
 
caterham_wwwConnect With a Mentor Commented:
> so the $ means just the root?

yes, it terminates the string. redirect 301 / http... will match everything but not RedirectMatch ^/$

> can i just add your

Yes, somewhere between <VirtualHost 199.999.999.99:80> and </Virtualhost>. Order doesn't matter.

> why do i need the 301?

That's the HTTP status code (moves permanently). A 302 status code (that's the default if you omit the status code) is not a good one for search engines (moved temporarily), except you'd like your page contents of http://othersite to appear under http://x.y.z.edu in search engines. That happens with a 302 status code.
0
 
Ghoti_AZCommented:
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.
0
 
chrismarxAuthor Commented:
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)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
caterham_wwwCommented:
with

  RedirectMatch 301 ^/$ http://othersite/

inside of your <virtualhost> for  x.y.z.edu
0
 
Ghoti_AZCommented:
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

0
 
chrismarxAuthor Commented:
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?
0
 
Ghoti_AZCommented:
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.
0
 
chrismarxAuthor Commented:
thanks!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.