How to redirect all sub-directories.

3 replies
Hello,

Say I have a domain - name.com

I create a directory at name.com/abc

Now, I want user to be redirected to another domain when ever user visit the name.com/abc folder, even if user visit name.com/abc/1 which does not exist, but once user reach the abc folder, anything sub-folder in it, user will be redirected, any one know how to do this.

Thanks
#redirect #subdirectories
  • Profile picture of the author Cram
    make an index.php file
    and put this in it.

    Code:
    <?php
    
       header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    
    ?>
    replaced "http://www.yoursite.com/new_page.html" with where you want the user to go.
    {{ DiscussionBoard.errors[6613450].message }}
  • Profile picture of the author John Ayling
    If you want to redirect a user even there isn't a sub-folder, then placing an index.php in the root won't work.

    You need to be able to redirect the user's request, and in php you can do that by adding or updating the .htaccess file in the root.

    Use this tool to craft up a redirect - Free .htaccess Redirect Generator
    Signature
    Software Marketing & Licensing System for WordPress Plugins, Themes & .NET Software
    >> 72 Hour Special <<
    {{ DiscussionBoard.errors[6617895].message }}
  • Profile picture of the author coderdave
    in .htaccess
    RewriteEngine on
    RewriteRule ^abc/(.*)$ http;//yoursite.com [R]
    {{ DiscussionBoard.errors[6620301].message }}

Trending Topics