2 of my urls, for example www.abc.com and www.def.com point to the same .php file. I have some text on that target page that needs to be dynamically changed depending on whether it came from www.abc.com or www.def.com. Can this be done? How?
See $_SERVER['HTTP_HOST'] for the host name of the current request.
In Apache's configuration, configure both hostnames to point to the same directory. If this is not possible, because you are on shared hosting for example, then you may still be able to use symlinks for both hostnames.
In PHP, you can determine the hostname that was used with the variable $_SERVER['HTTP_HOST'].
Related
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.
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.
I'm looking for a way to get a page address exactly how it is displayed in the address bar of the browser.
My site is basically a PHP script and my goal is to determine if the users use http://mysite.com or http://www.mysite.com or just mysite.com or www.mysite.com to access the site. I hope to use this information to redirect the link so it would be in a single format. This is required for some third party tools I'm using.
so what I'm askin is if it's possible to get the url of a site, in PHP exactly how the browser is requesting it.
You can tell the difference between www.mysite.com and mysite.com by looking at $_SERVER['HTTP_HOST'], however the browser will always automatically add http:// to a URL (and some browsers hide it from the users as unnecessary information) so there's no way to know what they actually typed in.
The first two lines of an HTTP request look like:
GET /index.php
Host: www.mysite.com
The first line specifies the local resource (usually a file in your web directory), and the second specifies what hostname the user entered to find your site (this is especially useful for servers running multiple virtual web hosts). PHP allows you to extract both of these:
$_SERVER['HTTP_HOST']
$_SERVER['PHP_SELF']
Technically, $_SERVER['PHP_SELF'] specifies the filepath of the current PHP script relative to the root directory of this web host, but that should, in practice, be the same as the resource listed on the first line of the HTTP request.
As the other responses have mentioned, there's no way to tell whether the user typed http:// or not.
You cannot determine whether or not the user typed http:// or left it off directly from PHP. PHP will only be able to tell the final domain name ($_SERVER['HTTP_HOST']). The other functionality is handled in the browser.
I installed OpenScholar in my domain:
http://scholar.web
Basically, when someone register for an account, his site URL is http://scholar.web/user, and his content will be at http://scholar.web/user/contents
I've been searching a way so that the URL is converted into: http://user.scholar.web/content for displaying his content via virtual subdomain (htaccess maybe)
Anyone can provide some solutions or guidance?
thanks
First of all, you'll need to change the DNS entry on the domain so that *.scholar.web points to your site.
Afterwards, (If you're using Apache) change the Apache vhost to accept *.scholar.web requests.
You can then use htaccess and/or PHP to do what you like with the URL formatting.
I used to have a domain called something along the lines of "iscool.com".
This is the method I used so I could use pseudo subdomains like "ben.iscool.com" and it would display content accordingly.
I need help in making my web page work on a public domain. I uploaded all my files & directories to root folder. How can I specify which file to open i.e. my user interface when url is opened.
I'm not sure I understand your question, but the default file name(s) that the web server looks for when you enter a domain name or directory without a file name are usually
index.htm
index.html
index.php (if PHP is installed)
(As #T.J. points out, differing additional names are used on Microsoft servers)
give a file one of these names and it will appear automatically.
Assuming Apache: take a look at DirectoryIndex