Mobile app version of vmapp.org
Login or Join
Kaufman445

: Redirect/rewrite dynamic URL to sub-domain and create DNS for subdomain I have created an application in PHP, I would like to re-direct the following URL to corresponding sub-domain. Dynamic

@Kaufman445

Posted in: #Dns #Htaccess #ModRewrite #Redirects #Subdomain

I have created an application in PHP, I would like to re-direct the following URL to corresponding sub-domain.

Dynamic URL pattern:
mydomain.com/mypage.php?user_name=testuser

I wish to re-direct this to the corresponding sub domain:
testuser.mydomain.com/


How do I create a rewrite rule for this purpose?
How do I register DNS for sub-domain without using CPANEL? (I want to
activate sub-domain when the user registers to the system.)

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kaufman445

2 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel251

You need to use a wildcard DNS rule for the subdomains, then you can do a rewrite rule to redirect that link to the correct domain.

Information on this can be found here: www.thecpaneladmin.com/setting-up-wildcard-dns-with-cpanel/
You will need access to the configuration files so it may not be easy depending on your host and hosting plan.

10% popularity Vote Up Vote Down


 

@Murray432

Take a look at this thread over at webmaster world

You'll need to create:-


A DNS mapping: *.yourdomain.com => your IP
A server alias *.yourdomain.com in your virtualhost configuration


.htaccess file with something like:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^user.example.com [NC]
RewriteRule ^(.*)$ /user [R=301,L]


You can replace user with ([a-z]) and use it in the rewriteRule. That way you can have a general mapping: something.yourdomain.com => yourdomain.com/user, even if the user isn't signed up to your site.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme