More than 800+ satisfied clients and counting, since 2010

Blog

How to redirect folder to a subdomain?

Recently I had to redirect my Joomla Store website from a folder – “http://www.infyways.com/store” in the hostgator hosting to subdomain – “http://store.infyways.com“. After searching on Google  I found that the only way to redirect the site is to modify the .htaccess file present in the root folder. I tried to add the rules as mentioned in the websites but got internal server error 500 or the redirection falied most of the time.

After going through some of the Apache HTTP rules and studied about the RedirectMatch rule for a while, the following code worked  for me without any issues. So here is how to redirect folder to a subdomain.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/subfolder/(.*)$ http://subdomain.example.com/$1

Replace “example.com” with your domain name, subfolder  to subdomain .Just replace the words that has been mentioned above and it would work perfectly. It is not that it will only work for the Joomla websites but also for wordpress, Magento and all the websites which run on apache server. Please keep it in mind that you have to add the code to the .htaccess file of the root domain, not the .htaccess file that you inside the subfolder.

Feel free to comment and write us below if you face issues with redirection.

Written by

The author didnt add any Information to his profile yet