[Last Call] Learn how to a build a cloud-first strategyRegister Now


Redirect just the root location of virtual host

Posted on 2008-11-07
Medium Priority
Last Modified: 2012-05-05
I have a virtual host


and i have many sites that use it


but i need to redirect request for


to another site. How do i do this in the apache httpd.conf?
Question by:chrismarx
  • 3
  • 3
  • 2

Expert Comment

ID: 22909156
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.

Author Comment

ID: 22909174
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)
LVL 27

Expert Comment

ID: 22909179

  RedirectMatch 301 ^/$ http://othersite/

inside of your <virtualhost> for  x.y.z.edu
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.


Expert Comment

ID: 22909211
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


Author Comment

ID: 22909232
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?

Expert Comment

ID: 22909268
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.
LVL 27

Accepted Solution

caterham_www earned 2000 total points
ID: 22909275
> 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.

Author Closing Comment

ID: 31514557

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question