Can I dynamically create subdomains (PHP, .htaccess) with GoDaddy Hosting? - php

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 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.

Related

Symfony2 routing domain virtual host

I haven't found any solution to my problem with symfony and virtual hosts.
I have one website www.example.com and have routes that have different contents based on an id.
Example:
www.example.com/id/1 is one website with menus that point to subpages:
www.example.com/id/1/page1
www.example.com/id/1/page2
www.example.com/id/1/page3
what I want is to set a new domain that points to this website with id 1 and another domain that points to id 2, etc.
For example:
www.newdomain.com shows content from www.example/id/1
www.newdomain.com/page1 shows content from www.example/id/1/page1
www.newdomain.com/page2 shows content from www.example/id/1/page2
www.differentdomain.com shows content from www.example/id/2
www.differentdomain.com/page1 shows content from www.example/id/2/page1
...
First of all, you just have to point both virtual host configurations to the same folder to make both URLs work.
But the virtual host setting is just one side of the configuration. You won't be able to configure the actual behaviour of the application regarding the different incoming URLs. I don't know if this can also be achieved via .htaccess settings, but you can definitely check in the controller of your application from what URL the request was send and then forward the user accordingly.

Redirect and URL Mask all non-existing/existing subdomains to homepage

A website example.com has one subdomain a.example.com. The point here is I want to redirect all existing and non existing subdomain (ex- b.example.com) to example.com without changing URL(URL MASK). To explain it more further, when a user enters b.example.com he must see example.com on his screen but URL must not change from b.example.com --> example.com. I think its possible from .htaccess file but I failed to achieve it.
Do I need to configure virtual host. Since I only have access to .htacces, I wish I can get it done
You need to have two things configured correctly:
A DNS entry with wildcard (*.example.com -> your server IP)
A virtual host with wildcard alias (ServerAlias *.example.com)
Then there is nothing to do in .htaccess. .htaccess alone can't do what you want. And please note also that this could be SEO-toxic (duplicate content), but it depends on your use case.
As you do not have access to virutal hosts config, may be you could go with subfolders instead of subdomains.

How to have different /servers with same Domain?

I have a website foo.com on wordpress and I want to do this foo.com/mexico, foo.com/venezuela, delivery different /server for each city with the same domain (without wordpress multisite).
I'm not asking about to detect ip by city but server and/or domain/dns configuration to do that.
I know there is other ways to accomplish this, but want to know about this one.
Here is an example:
http://www.vice.com/pt_br
http://www.vice.com/es_co
EDIT SOLUTION
This was my solution:
Create a subdomain, example.foo.com pointing to another server.
Create a folder on the main server with the name i wanted for the
link, for example 'mexico'
Inside this folder created a .htaccess:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/mexico
RewriteRule ^(.*)$ http:// example. foo. com/$1 [R=301,L,P
This works for me. If i want another /server i just repeat with another name, example 'venezuela'. The subdomain name will be hide by the .htaccess and this 'example.foo.com' will look like this 'foo.com/venezuela'.
What you are describing is a reverse proxy.
You can set it up using apache's extension mod_proxy. Personally I haven't touched that, but my opinionated answer would be to suggest you have a look at nginx. It's a dead simple reverse proxy. You can easily run nginx in front of apache, intercepting requests and passing them on to different servers or just send html-files directly.
A nginx-config can be as simple as:
server {
listen 80;
server_name example.org www.example.org;
location /mexico/ {
# We could have an apache server running on another port...
proxy_pass http://127.0.0.1:8000;
}
location /venezuela/ {
proxy_pass http://123.123.123.123:8000; # ...or another server.
}
location /bulgaria/ {
# Or just serve some static files
# In apache, do you set up a virtual host for this? christ.
root /var/www/static_html;
# If static html is all you have, what is apache even doing
# on your server? Uninstall it already! (As I said; opionated!)
}
}
edit: Finding my own answer after a few years, I'd just like to add that the 301-rewrite rule that OP choose to go with adds another request that the browser must wait for before getting redirected to the real address. 301-requests are still to this day considered bad SEO, and adds some (usually minor) loading time.
You will need to use subdomains, and set the A records at your domain registrar to map each subdomain to the different servers.
Here is a related SO question. Note, it was closed, but the selected answer is what your going for: Subdomain on different host
one.yourdomain.com --> points to ServerA
two.yourdomain.com --> points to ServerB
There is info on GoDaddy's site too. If your not using GoDaddy, the process would be similar: https://support.godaddy.com/help/article/4080/managing-a-domain-names-subdomains
You go into your domain registrar where you can edit your domain settings. It will probably be in something about DNS. Your wanting to add a new "A Record".
Some registrars simply let you put in "yoursubdomain", the IP of the server, and the TTL (Time To Live).
So enter your the subdomain for your first one, the IP of the server you want it to point to, and the TTL (if it asks) which is usually 3600.
Then add another "A Record", only for your other subdomain, the IP for that server, and TTL.
Repeat for however many subdomains and servers you need.
your solutions is:
1.You can use A record & subdomains for every server.
2.You can use your webserver configuration to relay user to destination servers (Apache,NGINX & etc)
But here I see you'r asking about Wordpress from multi server. You can only have multi server for your static contents (CDN), but your database must be in one place except you want to use cloud DB.

changing my ip based url to name based url

basically i have my website under 91.xx.xx.76/mywebsite in folder /var/www/mywebsite
and i want the user to type www.mywebsite.com, i have search some methods in doing so but doesn't actually solve it. they say to create a file under sites-available then enabled it
i have created file under sites-available and also enabled it using a2ensite mywebsite, then restarted apache2 using service apache2 restart then i try to load www.website.com but it loads nothing..
any help?
thanks
To use "name based URLs", you need to register the domain you wish to use in the global Domain Name System (DNS). Just setting some configuration in your own server is not enough; anybody could do that, which means there could be any number of people claiming the domain www.website.com at the same time. That's not how it works.
Find yourself a domain name registrar whom you'll wire a small amount of money in exchange for registering your desired domain. This purchases you the rights to set the DNS configuration of said domain to point its A record to your server's IP address.* This is what enables you to resolve www.website.com to your server. Then you only need to configure your server appropriately to serve requests for www.website.com.
* More correctly, it purchases you the right to set the NS record of the domain to point to a name server you control on which you can set any number of DNS records you want, including the A record. Most registrars also offer a name server as part of the deal of purchasing a domain, but those are actually separate things.

How to disable cPanel URLs

I use cPanel for hosting my website. I have noticed that if anyone who visits my website happens to be a web developer, he can always reach my cPanel Login page via mydomain.com:2082, mydomain.com/cpanel, etc.. It is better to not let the visitors know what control panel I use. I want to disable these URLs. To myself log in to cpanel, I will use the alternate URL provided by my Web Host which is something like a.myhost.com/cpanel.
As a work around, I also changed the main domain and added my main website as an addon domain. But even that didn't work and addondomain.com:2082 and addondomain.com/cpanel showed up the cpanel login and I was able to login there using cpanel username and password.
Please help me hide these pages from the public world. At least addondomain.com:2082 or addondomain.com/cpanel should throw a 404(preferable) or 403 or anything.
I use cPanel 11/x3.
Even my hosting provider is not able to help me with this. Anybody who know anything about this, or implemented this, please help me.
Thanks in advance....
Changing default cPanel port.
The cPanel port can be changed in /var/cpanel/cpanel.config file.
Just change port=2082 (located in the config file) to anything else.
Then running the following commands for the changes to take effect.
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
/etc/init.d/httpd restart
Changing/removing default cPanel URLs.
For the /whm and /cpanel urls, remove/change these lines or similar matched lines located on the /usr/local/apache/conf/httpd.conf file:
ScriptAliasMatch ^/?cpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
ScriptAliasMatch ^/?webmail/?$ /usr/local/cpanel/cgi-sys/wredirect.cgi
ScriptAliasMatch ^/?whm/?$ /usr/local/cpanel/cgi-sys/whmredirect.cgi
Then run the following commands for the changes to take effect.
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
Source and more info
From a similar discussion raised on cPanel's Forums - "Changing cPanel URL?" (29 Nov 2010):
There is no way to change the port numbers for cPanel, the WebHost Manager or Webmail. The port numbers are hard-coded into cPanel and there is no configuration option that allows them to be changed.
Even if you edit the httpd.conf file and change the ScriptAlias directives that cause /cpanel, /webmail and /whm to work, they will still be accessible via ports 2082/2083, 2095/2096, and 2086/2087, respectively.
(With application, or package specific questions, your best port of call is initially their own forums/helpdesk rather than a general purpose community like StackOverflow.)
this can be easily done with TCP PORT filtering blocking.
Just filter out in iptables every 2082 (may be even 2083) TCP IN and you will have your cpanel port blocked.
You can reinstate it when needed adding an ALLOW directory to the same ports.
Please tell me if you need further help.
There are times you want to disable automatic to SSL connection while accessing WHM, cPanel, Webmail, so you can access cPanel/WHM via standard ports 2082 and 2086, this is pretty useful if you have SSL issue that's preventing you from loging into your server or cPanel account because it may unable to decrypt your stored password.
Login to WHM >> Tweak Setting >> Uncheck the following options under Redirection
Always redirect users to the ssl/tls ports when visiting /cpanel, /webmail, etc.
Also you have to uncheck the following option under Security in Tweak Settings.
Require SSL for all remote logins to cPanel, WHM and Webmail. This setting is recommended.
If you are unable to login to WHM backend, you can disable those options from the shell. SSH to the server as root.
SSH to your server as root
Open
# nano /var/cpanel/cpanel.config and set the following options to 0 (zero).
alwaysredirecttossl
requiressl
—-
alwaysredirecttossl=0
requiressl=0
—–
Save the file and exit.
Login to WHM as root
Under server configuration,
Click on Tweak settings
Click the Redirections tab
Check off button for Always redirect to SSL
save settings & that will be done
Can't you use cpanel to put a redirect on the /cpanel directory? Not sure how to get around 2082 w/o more privileges. Possibly your htaccess?
But really, chill out on the cpanel. No one cares that you make your life easier by using cpanel. Most people do. The only people who are going to know are, as you say, developers. And guess what, they use CPanel too.
If your hosting provider cannot help you with this, then you're out of luck. Advisable to set a .htaccess rule to redirect /cpanel to the homepage.
For your .htaccess:
Redirect /cpanel /
or if it fails,
Redirect /cpanel http://your-site.com
I guess you are in a shared hosting environment. Your best shot is to use an htaccess file, be careful!
the goal is to redirect any thing like : #http://your-site.tld/cpanel or to a #http://your-site.tld but do not redirect #http://your-provider.tld/cpanle
RedirectMatch 301 ^/cpanel/$ http://your-site.tld/
RewriteEngine On
RewriteCond %{SERVER_PORT} !^2082$
RewriteRule ^(.*)$ http://your-site.tld/folder/$1 [L,R]
As I said, test carefully!
I have the exact opposite problem, I just linked my domain mtkroms.com to my blogger website but whenever I try to access mywebsite.com/cpanel it redirects to my blogger blog with the 404 page not found :( due to this I cannot setup subdirectories

Categories