Results 1 to 5 of 5

Thread: htaccess redirect to a subdirectory?

  1. #1
    Join Date
    Sep 2007
    Posts
    3

    Default htaccess redirect to a subdirectory?

    Hi all,

    I am having some difficulty in redirecting the user from http://www.domain.com/index.html to http://www.domain.com/subfolder/ through .htaccess. I have been using the following code:

    Code:
    RewriteEngine On
    RewriteRule ^(.*)$ subfolder/$1 [L]
    But the problem is, when it redirects, the address bar remains: http://www.domain.com/ and I would like it to display the full new URL (with subdirectory). Plus, I would like to still be able to access other (non-Index) files on the root directory such as http://www.domain.com/test.html without it redirecting. Any help would be appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    1,498

    Default

    Is there a reason you don't want to just put a redirect in your index file?

  3. #3
    Join Date
    Sep 2007
    Posts
    3

    Default

    Well, currently that's what I'm doing using a JavaScript redirect on index.html, which works but I'd prefer instant and permanent redirect (I also heard that the JavaScript method is not recommended for search engines). I had initially used a PHP Index file to redirect, but people who had the old site and index.php cached in their browser did not see the changes, and I'm not sure how to add a session ID variable to the default index.php script to force cache refresh.

    I don't like to use META REFRESH method since the user then has issues when navigating "back" in different browsers. If you have a better recommended way, I would appreciate it. But, the index page is absolutely nothing and all of the site's contents lies within the subfolder, so I see no need to put up a visual redirect page on it.

  4. #4
    Join Date
    Sep 2007
    Posts
    19

    Default

    Without going through all the command syntax used in the .htaccess file, login to cPanel, and select Redirects under the Domains section.

    Populate the necessary fields (Redirection Type can be either 301 Permanent or 302 Temporary) and hit Add. It creates the necessary .htaccess file for you.

  5. #5
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    1,498

    Default

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.(.*)?$ http://domain.com/subfolder/ [r=301]
    This will redirect any attempt to access a file named index.something to your subfolder, whether the file exists or not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •