Saturday, April 11, 2015

Redirecting to sub-folder in Hostgator using .htaccess

Step 1)
Create .htaccess file under public_html folder and paste the following code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?main\-yourdomainname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/sub\-folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sub-folder/$1
RewriteCond %{HTTP_HOST} ^(www.)?main\-yourdomainname.com$ [NC]
RewriteRule ^(/)?$ sub-folder/index.php [L]

Step 2)
Open wp-config.php and paste the following code.
define('WP_HOME','http://yourdomainame.com/');
define('WP_SITEURL','http://yourdomainame.com/sub-folder');

Step 3)
Copy your index.php from sub-folder and paste it under public_folder and add the following code
require( dirname( __FILE__ ) . '/sub-folder/wp-blog-header.php' );

BINGO!!!
Refresh the url in your browser: www.yourdomainname.com and it should work!

Ref: http://webmaxformance.com/blog/web-development/setting-wp-subfolder-points-root-hostgator-account