I want to dynamically create new sub domains on my website. i mean if you have example.com then you dynamically create sub.example.com .
i looked on google and there was nothing really good. i downloaded some scripts but they were all not working. my website is based on php so please if there is anyway i can do it in php tell me, and also if it can be possible with python then that is awesome!.
You need to setup a wildcard subdomain. Basically, anything.mysite.com will resolve to mysite.com. At that point it's up to your code to kick in and serve up the proper content depending on what subdomain the user is looking at.
http://www.google.lk/search?q=wildcard+subdomain
You can't do this unless you have permission to alter the DNS server for your domain.
Related
I want to allow the users of my PHP application to create their own subdomains on my server.
For example, I currently operate example.com and for my premium users I manually create a subdomain like bob.example.com or jack.example.com, I point the user subdomains to the same server that runs my application which has a wildcard SSL cert.
What I want to do is have a system that will automatically create subdomains of my domain for my users when they register on my application but I'm not sure where to start on this. I'm assuming that this can't be done purely in PHP but I'm hoping someone can point me in the right direction for what I want to do here.
Thank you N.B - Wildcard domain seems to be exactly what I'm looking for.
I have WordPress installed and running on GAE and have added my own custom domain via Google Apps. This is great but my appspot.com url is still publicly accessible and searchable.
How would I go about blocking this and redirecting to my custom domain?
I imagine it involves adding a url handler in the app.yaml file that points to a php file. I have no idea what would go inside though.
Also, how would I then go about setting up a 301 redirect for website canonisation and SEO that accounts for SSL and cron entries?
Any help is appreciated, thanks!
The appspot.com URL is always accessible and there is no way to turn it off. You can't do much in the app.yaml since it's not aware of the custom domain. I'm not really a PHP guy but you should do is to write manually the redirect based on the host URL if you really want to do that. Since you're using WordPress you might need to do quite some work if you don't want to redirect only from the root, but from any page.
Personally I think you should just leave it there and do nothing, even Khan Academy is not redirecting (http://khan-academy.appspot.com) and I'm pretty sure that very few are actually doing that.
I really appreciate any answer to my question because I am searching for this about two weeks. My goal is to create directories using PHP and displaying them as a virtual subdomain (All procedure should have done automatically).
For example :
example.com/test/index.php should be considered as :
test.example.com/index.php
The only way I was able to do such thing was using a wildcard subdomain. If your server supports that, it's just a matter of using a front controller to manage the requests.
You cannot do this solely with PHP. You need dynamic shell scripting to create the DNS zone files for each subdomain.
EDIT:
Probably #Robyflc is right, you can base conditions on the host name in PHP. It is not clear form the question if you want the subdomain or just some logic like create a URL user1.domain.com and then find the folder depending on the value of it.
To do that, I recommand you to buy a VPS server
it's possible with URL Rewriting.
I understand that there may be other questions regarding vanity urls but everyone i see has a different code that i guess does the same job. Therefor i do not understand what rules are best for my personal question, that being said here is my question.
I simply want to create this,
127.0.0.1/website/profile.php?id=1
To this,
127.0.0.1/website/profile/Admin
My sub questions are also,
I understand the .htaccess file has to be in the root directory, but is that the root of my website or my xampp htdocs?(e.g c:/xampp/htdocs/ or c:/xampp/htdocs/website)
Using php should i make the conversion between id to username for the URLS on a seperate file then redirect to the requested user's page?
Thank you for reading, i just can't seem to get my head around .htaccess!
Root directory of your website.
No need for redirects. The way it works is that you can map every section of your URL to a URL parameter. For example, http://localhost/profile/Admin is really interpreted as http://localhost/website/profile.php?username=Admin. Only users will see the vanity URL; PHP will still see the URL parameters. In your case, the .htaccess rule will look something like ^profile/([0-9]+)$ profile.php?username=$1 (I obviously don't know for sure since I don't know the architecture of you site).
On a side note you might find Virtual Hosts interesting. It's a way of being able to create your own local domain for your site, for example http://my-local-website instead of using http://localhost/website or waiting to test in production.
More info here: http://sawmac.com/xampp/virtualhosts/
I have a web app of which I would like to create a mobile version with jQuery Mobile. The existing application is built in CodeIgniter; I'll be using the same controllers, models where I can; (especially models since I'll be needing the same data anyway, might have to write new controllers).
I'm a bit confused as to how to get started. I want to put my mobile version on a subdomain (m.myhost.tld), however.. since my app is at www.myhost.tld and I don't feel like copying it all over to another folder and maintain two, I'm a bit confused.
I know I can use the User Agent library in CodeIgniter to detect mobile browsers and load views accordingly; I just don't know how to get this working with a subdomain. Do I need to customize my app/config/routes.php file here, or can I fix this with some .htaccess magic? I have next to none experience with .htaccess though. The only thing I know is how to remove my index.php from CI apps, and that's a copypasta snippet.
EDIT: I wonder if I can use a tutorial like this one to do what I want to do? It seems to be doing more or less the same thing, just with dynamic usernames instead of a simple 'm.'
EDIT 2: Some more information, I guess.
Say I detect mobile browsers using the User Agent library included with CodeIgniter. I want to direct these browsers to m.myhost.tld. However, the content that I want to display on the mobile website comes from a controller called mobile which I can also access through www.myhost.tld/mobile/; so my question is if there is a way to route a URL like.. for example www.myhost.tld/mobile/about to m.myhost.tld/about. I'm not even sure if this is possible, teehee. Still learning!
I'll be grateful for any advice you can give me. Thanks a lot!
If you want to share the same files in different hosts, you must assign the document root folder of your sites in your web server, this is an explanation for static files, but is the base to you understand.
browser -> host:z.y.xxx[ip.ip.ip.ip] -> web server -> read filesystem : document root + browser request path
so if your document root is:
/hosting/http/z.y.xxx/htdocs
and the request is /path-to-static/index.html the server try to read:
/hosting/http/z.y.xxx/htdocs/path-to-static/index.html
In conclution, you create the new host m.mysite.tld in your web server and you change the document root as the same of the you www.mysite.tld also you could use directives of host alias, like Apache ServerAlias directive. Have lot of documentation to how you could configure a web server.
You could handle the host name in php with $_SERVER['HTTP_HOST'] variable.
If you could specify more, I could help more.
have a nice day