Search code examples
php.htaccesshttphttp-redirecturl-routing

localhost redirect to specific folder according to the parameter passed


I have WAMP Server, and inside the WWW folder I have two folders

1 ) App_A
2)  App_B

What I want is, if some one type the url http://localhost - It should redirect to App_B Folder, But if some one writes http://localhost/test, then I want to re-direct to App_A. How do I achieve that?

I have made the following code but not working...

<?php
if(empty($_GET['test'])) {
    header("http://localhost/App_A");
}
else {
    header("http://localhost/App_B");
}
?>

Thanks


Solution

  • Make .htaccess file in your root directory, which is: www folder. Put the following content inside that .htaccess file:

    RewriteEngine On
    RewriteRule ^$ http://localhost/App_B [L,R=301]
    RewriteRule ^test$ http://localhost/App_A [L,R=301]
    

    .htaccess is used for URL rewriting. In the code above, / is rewritten to /App_B and /test is rewritten to /App_A