I am trying to use a combination of .htaccess and PHP to create subdomains on-the-fly on my GoDaddy Hosting account. I've run into a problem of trying to modify the zone using the wildcard asterisk. I am not at all familiar with how this works and have only found the zone stuff about the domain by exploring the domain manager extensively. I'm not sure I know what I'm doing. I'm slightly more acquainted with .htaccess, although it's still a big challenge for me to write RegEx.
I've researched another tutorial that will use .htaccess to reroute a subdomain to a folder in the root of my domain (e.g. sub.domain.com to domain.com/sub). Here's my code:
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+).MY-DOMAIN.com$
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www)$
#Check if the directory actually exists before we go there
RewriteCond /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 -d
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/
#Finally, this is the actual rewrite
RewriteRule (.*) /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 [L]
As of right now, I've done the following:
- Logged into GoDaddy Domain Manager.
- Went to Tools > DNS Manager.
- Opened the Zone File Editor for my domain.
- Added an A (Host) Record with Host Name * and in Points to IP开发者_如何学Go Address I copied the value from the @ entry's IP address, since that should be the same as my domain...?
- Now, after waiting until the nameservers or whatever updated and propogated and stuff, I get a 403 error when I try to access a subdomain.
Any suggestions?
DNS is only 1 part of the configuration. You need to have a ServerAlias for *.mydomain.com in the configuration for the virtual host in Apache, otherwise Apache will not have any idea where to route requests for *.mydomain.com - which means the .htaccess never has a chance to work at all.
If GoDaddy provides a way to manually edit your virtual hosts' directives, or at least the ability to add server aliases through their GUI, then it's easy enough. If you can't find it, you should contact GoDaddy for information.
I was advised to move my answer from here to this question:
While not the same as being able to create a new vhost entry for each subdomain dynamically added, you should be able to set this up using a Wildcard DNS record and adding a dedicated IP to your hosting account. You can add a dedicated IP to your hosting account using this method:
- Click Web Hosting.
- Click Options, and then click Customize tab.
- From the Server IP menu, select Dedicated.
- If you already purchased a dedicated IP address credit, click Apply Dedicated IP Credit. OR If you need a dedicated IP address credit, click Checkout, and then complete your purchase.
NOTE: Dedicated IPs can take 24 hours to become active on your hosting account.
You can setup *.yourdomain.com to use the dedicated IP of your shared hosting account in our DNS Manager.
- Go to the Zone File Editor for the domain name you want to update.
- Click Add New Record. The Add DNS Record window displays.
- From the Record type list, select A (Host).
- Complete the following fields: Host Name — Enter * Points to IP Address — Enter the Dedicated IP address of your hosting account. TTL — Select how long the server should cache the information.
- Click OK.
- Click Save Zone File, and then click OK. The new A record displays in the A (Host) section.
I just got off the phone with GoDaddy tech support, and was given a brilliant solution that doesn't require using mod_rewrite or upgrading to a dedicated server.
From your account login at https://gateway.godaddy.com select Hosting from the dropdown and then on the page that opens, select Settings. In the modal window that opens, click the Change Domain button and enter in a dummy domain (note the dummy domain does not need to be registered or entered in DNS. This will then change your default domain to the dummy domain which will reside in the public_html folder.
After you have done that, go to the cPanel and choose Addon Domains from the green menu bar at the top. Enter a new domain and type the name of your registered domain, then specify the document root (DocRoot). The path can be a directory location completely outside of the public_html folder so you can create a Laravel friendly path such as webroot/mydomain.com/public and install Laravel in webroot/mydomain.com.
Likewise, you can specify similar paths for subdomains.
Hope this helps everyone looking at this.
精彩评论