1

Is there any easiest way to create a sub domain using PHP code on godaddy.com hosting?

e.g:

jon.mywebsite.com
jessie.mywebsite.com

etc

Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51

3 Answers3

1

you need to create a A record to serve all your subdomains

*.your-site.com       IN  A       YOUR-IP-ADDRESS

then you need to create a .htaccess file and

RewriteCond {REQUEST_URI} !\.(png|gif|jpg)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?uri=$1&hostName=%{HTTP_HOST}

this will ignore images (SEO friendly URLs).

Now you can redirect your users to $userName.your-site.com

Alternatively try this:

setup your application so your users goes to your-site.com/user your .htaccess should look like this

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([aA-zZ])$  index.php?username=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.mywebsite.com
RewriteRule (.*)  index.php?username=%1

so now when you hit the index.php it will grab the user and redirect to $user.your-site.com as a custom subdomain. (in this case usernames are limited to a-z characters)

Eddy Ferreira
  • 770
  • 8
  • 14
  • I've setuped the A record but, .htaccess is not pointing me to the required page – Muaaz Khalid Feb 09 '14 at 09:50
  • I've edited the answer, take a look at the alternative method, hope that helps – Eddy Ferreira Feb 09 '14 at 09:59
  • Still same... nothing happen.. I can just see there "pageok" – Muaaz Khalid Feb 09 '14 at 10:21
  • @muaaz,when exactly are you are getting "pageok"? and what does that mean? I'm assuming this is a godaddy generic page and you followed the steps I mentioned above and everything works as desired. – Eddy Ferreira Feb 10 '14 at 22:34
  • it means, sub-domain is not being pointed to any location in my hosting.. I just came to know that, I need to buy WildCard certificate to achieve the goal. – Muaaz Khalid Feb 11 '14 at 04:01
  • oooh #GodaddyCommercialism, @muaaz I suggest you look at dedicated cloud services like VPS(Virtual private services)/AWS amazon etc... you will need a bit of linux familiarity (which you can reference to on youtube/books)to get started but it will save you lots of money in the long run. – Eddy Ferreira Feb 11 '14 at 10:25
0

I dont think with PHP Code you can but with the help of .htaccess i think it is possible.

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+jon/
RewriteRule ^jon/(.*)$ http://jon.mywebsite.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} \ /+jessie/
RewriteRule ^jessie/(.*)$ http://jessie.mywebsite.com/$1 [L,R=301]

RewriteRule ^(jon|jessie)/ - [L]

RewriteCond %{HTTP_HOST} ^(www\.)?jon\.mywebsite\.com$ [NC]
RewriteRule ^(.*)$ /jon/$1 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?jessie\.mywebsite\.com$ [NC]
RewriteRule ^(.*)$ /jessie/$1 [L]

You can make subdomain much easier using control panel, why to do it the hard way ?

Akhil Sidharth
  • 746
  • 1
  • 6
  • 16
  • well, that's also acceptable. BUT, I need it to be general like if I have url like this http://www.username.mywebsite.com using htaccess it should point me to http://www.mywebsite.com/username username can be vary – Muaaz Khalid Feb 09 '14 at 06:36
0

This is an old question, but in case anyone is looking for the answer. This is specific to GoDaddy, but other Hosts may do something similar to this.

After you setup your DNS A record you need to go to Hosted Domains and add the subdomain folder name under the root domain account. Go to Hosted Domains. Under Hosted Domains you will see a root domain table column. You will also see a Subdomains table column with an "Add" link. This link is for adding subdomains to a root domain. Type in/enter the name of the subdomain folder.

Create either an index.php or index.html file and upload it to your subdomain folder and echo something like "Setup Completed". I noticed that if you are doing something like creating a restricted "api" subdomain for example and the GD script cannot access the index file in your subdomain folder then the "process" does not complete until you add a plain index.php or index.html file in your subdomain folder. After that is done then you can add anything you want in that subdomain folder/site.

Ed-AITpro
  • 310
  • 1
  • 8