I own a website which gives every registered user a dedicated space like this:
www.mywebpage.com/user1
www.mywebpage.com/user2
www.mywebpage.com/user3
Inside this path the user has his mini web site.
I'd like to give my users not a path within my domain, but a second level domain like this:
user1.mywebpage.com
user2.mywebpage.com
user3.mywebpage.com
A lot of websites do this, but I can't figure out how to get it!
Am I supposed to register a CNAME in my dns record for every single user? How the hell can I achieve this with PHP? I don't think it's possible to configure godaddy with a human-hand written script.
I may register an alias CNAME which points every second level domain to my top domain, and then check within my top domain the first token of the url retrieving the user: but now I can't redirect him on a new page (which is the index of his subsite) or I'd lost the web url userx.mywebpage.com.
How can I handle this? I'd appreciate any hint about the right path to follow in order to achieve my goal.
Create a wildcard A record (*.mywebpage.com) pointing to the IP of your server.
Create an Apache virtual host for ServerName *.mywebpage.com, pointing all requests to the same document root. Your script looks at the hostname to know which user's site it is. You do not need to redirect outside of the user's subdomain. If your script sees the subdomain is "www", that's your special case where you display the main website instead of the user's stuff.
The feature you want to see is often called Wildcard sudomain (usually blog sites have this feature).
Usually you make a CNAME record of * to represent the wildcard subdomain. Instead, with Godaddy make an A record with the name * and set the IP to your server. We have done with our ASP.net website in the past (not sure if works with GoDaddy still but give a try).
With a very little knowledge on PHP I can suggest adding some redirection(URL Rewrite) configuration in your httpd.conf or apache.conf file.
Please check this
http://kbeezie.com/view/wildcard-subdomains-php/
after this you can write your own logic. All you need to do is find out your user from db which is in the subdomain name and render the pages.
You don´t have to set up dns entries for what you´re trying to achive. Depending on how much control you have over your website, in case you´re using Apache you can easily set up virtual hosts for your subdomains (see http://content.websitegear.com/article/subdomain_setup.htm)
Related
I have registered a wildcard subdomain record for the dir /.../public_html/hosting/accounts/. When a user requests a hosting space, I generate a folder in accounts. My index.php (which is also the 404 ErrorDocument) in accounts uses some basic PHP code to determine the subdomain and the path. Using display the file using include({subdomain}/{requested file}).
Therefore, demo.example.com/file would trigger a 404 and the index.php will display the file at example.com/hosting/accounts/demo/file.
I am, however, concerned that the users would be able to access the files of others via get_file_contents, include, exec and etc.
Is this the correct way to provide hosting on a subdomain? Is there another way to do it?
Any assistance would be appreciated!
I've set up HybridAuth on my webserver. I have a basic html page that displays 3 log in options for either Google, Facebook, or Twitter. For testing on my home pc, I set the config.php file to read:
"base_url" => "http://my.local.ip.address/hybridauth-2.1.2/hybridauth/index.php",
So far, with this set up, selecting the Sign in with Twitter option does work and I can grab some basic profile info from the user. However, Facebook returns the following message:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
When trying Google it returns this:
-Invalid parameter value for redirect_uri: Raw IP addresses not allowed: http://my.local.ip.address/hybridauth-2.1.2/hybridauth/?hauth.done=Google
As a note for above, "my.local.ip.address" was my actual local ip address but I was forced to change it here.
However, when I change the config.php to have what it should for normal use:
"base_url" => "http://myFQDN.com/hybridauth-2.1.2/hybridauth/index.php",
then I get on my phone (not on my local network) and it just reloads the base html page, no matter what option I select.
Any help or suggestions would be great.
Note: Port 80 is blocked from my ISP, thus so, I have it redirecting from my registrar to another port that is then forwarded inside my router. If it's possible this is the issue, please let me know as well. - Additionally, everything works fine when I'm just putting up a standard .html pages.
Thanks
I don't think that most of the OAuth2 providers will accept answers that are not coming from configured callback url. So making redirects with the register will most likely fail.
Instead, try to configure your callback to look like:
http://www.yourdomain.com:openPort/hybridauth-2.1.2/hybridauth/index.php
Where openPort is a port number that your ISP will not block.
Then in the router you can make port forwarding openPort->80 or you just can start your web server to openPort and make sure the router is not blocking the requests.
if I like to create per user sub domain , how technically do I do this ?
for example if user XXX is registered to my site and I what to associated him the sub domain http://xxx.mydomain.com/
or http://www.mydomain.com/xxx/
what is the procedure to make it ?
You need to setup a wildcard DNS record to catch all subdomains and send them to you web server.
Then you need to setup Apache to catch all named virtual hosts and send it to a directory.
In the directory you would set htaccess to send all requests to one script which would read the sub domain from the server variables and handle it accordingly.
If you want mydomain.com/xxx, then that's just a folder. Some hosts will also take mydomain.com/xxx and automatically make xxx.mydomain.com point to it without needing any configuration on your part. Might want to check that this isn't already the case for you.
How would you create the subdomain manually?
Good. Now automate it.
Currently I have a .htaccess file within the directory of the folder I want to restrict, with the appropriate group that has access to it.
What I want to do is have one htaccess for the entire site, and restrict groups to specific URL's.
So I want staff to have access to:
/staff/..
and Students to have access to:
/students/..
I would prefer restricting by URL in the htaccess file, so I do not have to do it in the virtual host conf file, and restart service each time.
so i am guessing that your picking up the group from LDAP .. so as ur using PHP .. i am guessing u would have a top level include file for db connections etc. So u can pick up their group from the LDAP,store in session and in the include .. check that REQUEST_URI always goes to their relevant folder e.g /$_SESSION[group]/ .. if not redirect them there.
With htaccess, AFAIK, you would need a new htaccess for each of those folders. You could just create users with the same un/pw for each of the folders for continued access, but they would need to log in more than once.
Since you have this tagged under php, I can give you a better php solution :) Simply prompt the user for un/pw and create a session to set loggedin = 1 and you're good to go. If you want to make this secure, you should do it via db and include some sort of md5 security code in the session as well.
I have a php account with my provider, and I also have cpanel installed for me.
I currently have two drupal sites there, let's called the main myMainSite and another one under construction called myNewSite.
So when I go to www.myMainSite.com, I go to the main site. When I go to myNewSite.myMainSite.com, i go to the drupal site that is under construction.
My question is, when my under construction site goes live, I want that all users that go to www.myMainSite.com see the new site (the one that is under myNewSite.myMainSite.com).
How can I accomplish this with cpanel? is it within the "addon domains" configuration?
I don't want a redirect that changes the address bar, ie, I want to keep the original url.
You would just change the DocumentRoot of www.mainsite.com to point to the same DocumentRoot as myNewSite.myMainSite.com.
I assume you've used cPanel's subdomain control panel to add myNewSite.myMainSite.com. And I'll assume myMainSite.com is in the /public_html/ folder. Therefore the new site (and site with a subdomain) will be at /public_html/myNewSite.myMainSite.com
Why can't you just use File Manager (or FTP) to move all the files in /public_html/ to /public_html/OLDsite?
Then move everything from /public_html/myNewSite.myMainSite into the /public_html/ folder.
Then check your site is working with the new files.
Maybe you could also send a support ticket to your host to see if there's another way. It could be as simple as them changing something in Apache's conf file for the myNewSite.myMainSite.com subdomain.
I'd also think you'd need to change the settings in Drupal (when you've changed domain) so Drupal knows the new domain name too.
I recommend you to have main 2 user accounts call oldlive and newlive.
you may have domain like
oldlive.myMainSite.com and newlive.myMainSite.com
Then you can add Park Domain myMainSite.com to oldlive.myMainSite.com when you not ready.
Once you are completed new site which currently in newlive.myMainSite.com, you will remove park domain from oldlive.myMainSite.com and move to newlive.myMainSite.com.
then you can transfer domain smoothly.
You can use "Redirects" option in cPanel to redirect all visitors from old to new site.
Or you can simply change Virtualhost in Apache for your main domain to directory of your finished (currently under construction site).
Agree with the previous answer. If you would like to load the sub-domain's contents on the main site then you will need to move the data from sub-domain's directory to root directory that is public_html.
Just make sure, you do not have any live site on your main domain, If your main domain has the working site for it and you will upload the contents under the root directory then your website won't work due to conflict in contents.
If it's not possible then you will need to upload the contents under one sub-directory in public_html and after that you can access the site by yourP_website_name/directory name.
Once you will done with the moving contents then you will need to update the base UR Lto the new site URL.It is present in cPanel >> File Manager >> public_html >> Sites/Default/Settings.php