Redirect just the root location of virtual host

Posted on 2008-11-07
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
    LVL 5

    Expert Comment

    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

    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


      RedirectMatch 301 ^/$ http://othersite/

    inside of your <virtualhost> for
    LVL 5

    Expert Comment

    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 /

    Open in new window


    Author Comment

    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/

        ### 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?
    LVL 5

    Expert Comment

    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

    > 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 in search engines. That happens with a 302 status code.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Title # Comments Views Activity
    Employ management and Helpdesk software 4 24
    DNS Question 7 43
    Mysql timeout on my xampp install 21 57
    ports for sccm 2012 1 30
    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). #…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now