PHP hosting and URL display - php

I have a site using PHP and MySQL. I have a domain name reserved by a domain name provider. I do not want to use the storage proposed by that provider to store my files, because it's really too expensive.
Let's say the domain name is : www.domainname.com
So... If I choose another provider (let's imagine it's free.fr) to store my site's files, what may I do, or what may I look for, to be able to have in my url bar :
http://www.domainname.com/onefolder/onegreatfile.php
instead of :
http://imhere.free.fr/innerfreefrfolder/onefolder/onegreatfile.php
If I activate the transparent redirection on my domain name, the url keeps being :
http://www.domainname.com
If I force the url bar to go to http://www.domainname.com/onefolder/onegreatfile.php
it returns a 404 not found error (The requested URL /onefolder/onegreatfile.php was not found on this server.)

The following is an oversimplification but it should be enough to get you where you need to go:
You'll want to sign up with a web host that allows you to use your domain name with their server. They will tell you what to set your name servers to so that any requests for www.domainname.com will result in the ip address of the server your files are stored on. Setting the name servers for your domain is usually done via a service provided by your registrar.

The transparent redirection you're referring to (some hosting sites call it Forwarding with Masking) is really just your hosted files displaying within an iframe on your owned domain name.
What you really need to look into is setting the DNS servers/Nameservers for your domain name to point to your hosted website/IP address.

Related

Domaining with PHP

I have a site say abc.com and a user account is accessed at abc.com/user. Now I want to add functionality that user can link his site say user.com to abc.com/user. Can u please give me an overview that how this process can be done dynamically via php?
Set up DNS to point the host name at the server
Set up the server configuration so the site is the default virtual host (so if an unrecognised domain name is used to request it, the right site will be loaded)
Use $_SERVER['HTTP_HOST'] instead of the path.
If I understood correctly - you want that a person who is entering user.com will see the content from abc.com/user.
I would recommend checking out launchrock.com they do exactly this, and it involves adding a CNAME dns record as I remember, another way to do this is to create a Proxy flag rule in httpd (mod_proxy must be enabled for this), so that you won't have to restart the server, you can always the .htaccess in your www dir.
doing so dynamically will be easy if you go the proxy route, as you just need to append a new proxypass every time a new site is deployed, or create a parameterized rule, like a regular htaccess, as far as automating DNS records creation, I'm sure that's possible and maybe DNS provider such as godaddy or AWS have api for those kinds of things, but more research is required.

change DNS with php like as if editing hosts file?

I don't know how to phrase this better, mainly because I dont really know how DNS fully works.
Given a URL and an IP, is it possible to tell PHP to make all requests to that IP AS the given URL instead of the real DNS (Just as if you edited your hosts file locally)?
The only solution I see is to run your own bind server, and tell your clients to use your bind server. You then have full control how a name is routed to a IP.
Unfortunately for your case, you are at the whims of your client.
If they type the IP address in their browser it will work, if they type the domain which has not been set up in DNS or in their hosts files, it will never reach a server that you control.
If you have designed you site correctly, it probably really shouldn't matter if they access it via domain name or IP address.
I think this is what apache does via .htacess or other configuration files. That is not a "change" to the DNS, but a way to manage every request as you want, even with a unique and generic .php file

webpage hosted on a server which is pointed by separated domain name, how to hide original server path?

Am sure there's answer on Google but I don't know how to formulate my question:
A php website is hosted on server like this: http://sub.realserver.com/website/index.php
Now I want to link the real domain name to it: http://therealwebsite.com
Problem is, when user visits:http://therealwebsite.com, he will see http://sub.realserver.com/website/index.php as he browse through other pages.
Question is how do I hide this realserver path and replace it with the domain name?
Thanks
edit: the website is hosted on a different server as the real domain name
I presume the domain name and the web site are pointing to the same server.
Although you could use URL rewriting (works with almost all popular web servers), the better solution is to set up your web server to provide that web site for the root of that domain name. How to do that completely depends on what server software you are using.
In apache, you need to create a so-called Virtual Host, configure it to respond to your domain name and set its DocumentRoot directive to the directory where your site is located.
See http://httpd.apache.org/docs/2.0/vhosts/examples.html for an example.
EDIT: I just read your comment. I'm afraid your options are rather limited. The easiest solution, but also the most dirty one, is to create one page with an IFRAME on it, that loads the site from the real server. You could also host a PHP proxy and on the server that hosts your domain name, and let it proxy the site on your
http://sourceforge.net/projects/php-proxy/
(I never used this, nor am I affiliated with this project, but it seems to claim to do what you want.)
I highly recommend though that you update your DNS records on your domain name so that it points to your server that hosts your site, and that you add a virtual host there.
you can do this with asp, there is a good resource on it here -
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Masking URL in Status Bar

I'm hosting my own website on my personal server running Ubuntu server. My public IP address is showing up in the status bar each time someone visits my sites or hovers over one of the links on the pages (i.e. when going to the home page it says waiting for myipaddress/index.php). I have purchased a domain name with godaddy. While I was able to find the option of mask the url in the address bar in the admin page, I was able to find no such option for the status page. Initially, I tried to embed JavaScript code into the php files but I later learnt from various posts (link) that we cannot control what is displayed in the status bar .
All I want to do is to display my domain name instead of my IP address each time the page loads and each time the user hover's over a link. Any ideas of how I should go about this?
You should just have your domain name point to your IP address and setup the site on your server to handle that domain. Then all requests will go to that domain name instead of directly to your IP address.
Note: it's very easy to find the IP address for any web server (based on a domain name) so you can't really hide it, but you can set it up so that it behaves just like any regular site that uses a domain name instead of an IP address.
Have you done anything to connect the webserver and the domain name? You're going to need name servers, often your domain provider will have something you can use, or you can run your own. The name server is like a phone book for websites. It says mydomain.com can be found at IP address 123.whatever. Until you have an entry in a name server 'phone book' you will not be able to access it through that domain name.
You'll also need to setup something on the webserver so it will know what to serve when it gets a request pointed to that domain, if you're using apache, likely it will be a virtual host entry in the appropriate config file.

Manage Cookie on Multiple "Domains"

We have a local web server in our office that we use for some reporting and mundane order processing -- nothing major. I recently added some quick code to add a cookie to certain workstations so the user doesn't have log in all the time. The problem I am running in to is that since the server itself acts as an additional workstation, people can access it from http://127.0.0.1, http://localhost or http://192.168.1.111. This ends up creating three distinct cookie domains. Is there any way to configure the server to force one or the other? Or is my only option to move all bookmarks to point to the actual IP address and warn people not to use 127.0.0.1/localhost?
The server is running Apache 2.2 on Windows.
You could check the $_SERVER['HTTP_HOST'] and redirect the browser if a visitor hasn't gone in via the correct hostname.
if('servername' != $_SERVER['HTTP_HOST']) {
Location('http://servername/');
}
If you're running an internal DNS server, you can configure a host/domain name for the server without having to register it - since it's for internal use only, you don't need to expose the name to the rest of the world.
Even without a DNS server, you can add an entry to each machine's hosts file to do the name->ip mapping.
Configure your site to use that name, tell everyone to use that instead, and then the cookies will take care of themselves, since they'll all be set using that host/domain name. You can then add vhosts for the IP-only hits and redirect them to the new named address.
Typically cookies are set to domain names, not ip address. When using a domain name you can use a wildcard setting
.apple.com
Then any variation of that domain will accept the cookies.

Categories