How to set redirect from dynamic URL to suddomain ?

Started by Dipak Bhoi, September 18, 2014, 05:11:47 PM

Previous topic - Next topic

Dipak Bhoi

Hello Guys,

If you wish to re-direct the dynamic URL to corresponding sub-domain then let see how you can achieve this:

First you need to know the Dynamic URL pattern:
Quote
http://yourdomain.com/page.php?user_name=user1

Here in above URL word user1 is not a specific . It will change every time. And below is a URL that you wish to re-direct this URL to below corresponding sub domain.

Quote
http://user1.yourdomain.com/

Let see how you can do this :

1. First you need to set wildcard for your domain. You can do this by simply edit the line in your virtualhost configuration in httpd.conf file. Set it as below.

Quoteserver alias *.yourdomain.com

2. Save the file and restart httpd service.

3. Now write the below code into your .htaccess file.

QuoteRewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z])\.yourdomain\.com [NC]
RewriteRule ^(.*)$ /user1 [R=301,L]


Now it will redirect like something.yourdomain.com => yourdomain.com/user1.

That's all.

Enjoy !!


MilesWeb - 30-Day Money Back
cPanel Web Hosting - cPanel Hosting in India
Grab a Free SSL for your website.  WordPress Optimized Solution.