.htaccess 301 redirect subfolder to another domain?

Posted on 2012-08-11
Last Modified: 2012-08-12
How can I do a .htaccess 301 redirect to redirect a subfolder to another domain?

Question by:DantechIT
    LVL 2

    Accepted Solution

    here are some ways to do it.

    #1 put a .htaccess in a subfolder and it content will be:

    RewriteEngine on
    RewriteRule ^/?$ "http\:\/\/www\.domainname\.com" [R=301,L]

    in this way, the URL in the browser will change to

    #2 put a .php file in the subfolder and it name will be index.php, content will be:

    header("Location: $url");

    in this way, the URL in the browser will change to

    #3 if you do not want change the URL in browser, you need use iframe or reverse proxy

    Author Comment

    Thank you. When I do that it redirects but ads the original subfolder to the end, see example:

    if I put an .htaccess file in the folder

    RewriteEngine on
    RewriteRule ^/?$ "http\:\/\/www\.domainname\.com\/folder\/" [R=301,L]

    When I go to it redirects me to
    LVL 2

    Expert Comment

    RewriteEngine on
    RewriteRule ^/?$ "http\:\/\/www\.domainname\.com\/folder\/" [R=301,L]

    Open in new window

    the URL in second line is the target.
    If you just want redirects to, you do not need add \/folder\/

    Author Comment

    Disregard, I had a cache issue.

    Thank you for your help, it worked.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    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 …
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now