today im playing with domains with php,
example
www.wordpress.com is our main site
www.friend1.com is my new domain
www.friend2.com is my new domain
www.friend3.com is my new domain
to
www.friend1.com the same as www.wordpress.com/profile/friend1 ?
www.friend2.com the same as www.wordpress.com/profile/friend3 ?
www.friend3.com the same as www.wordpress.com/profile/friend2 ?
how do wordpress, etc do things like that? are they doing that in the server side ?
or there is a way doing stuff like that in php?
*edit
if you still dont get it,
heres a example. lets say you have a friend deviantart id at myfrienddeviantartid.devaintart.com and lets say you are the admin on deviantart. you want to make a addon service that your friend can park his own domain into deviantart.com.
This is traditionally done using mod_rewrite inside Apache's configuration. It remaps URLs.
For apache http server, it uses ProxyPassReverse directive from mod_proxy or directives from mod_rewrite
The directive ProxyPassReverse lets Apache adjust the URL in the
Location header on HTTP redirect responses. For instance this is
essential when Apache is used as a reverse proxy to avoid by-passing
the reverse proxy because of HTTP redirects on the backend servers
which stay behind the reverse proxy.
Suppose the local server has address http://wibble.org/; then
ProxyPass /mirror/foo/ http://foo.com/
ProxyPassReverse /mirror/foo/ http://foo.com/
will not only cause a local request for the
http://wibble.org/mirror/foo/bar to be internally converted into a
proxy request to http://foo.com/bar (the functionality ProxyPass
provides here). It also takes care of redirects the server foo.com
sends: when http://foo.com/bar is redirected by him to
http://foo.com/quux Apache adjusts this to
http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect
response to the client.
For MS(R) IIS use Re-Write Module:
Easily replace Web application URLs to produce user and search engine >friendly results.
URL Rewrite permits Web administrators to easily replace the URLs >generated by a Web application in the response HTML with a more user friendly and search engine friendly equivalent. Links can be modified in the HTML markup generated by a Web application behind a reverse proxy. URL Rewrite makes things easier for outbound response content and headers rewriting with outbound rewrite rules that work with HTTP request and response headers and with IIS server variables.
Additionaly, you must make sure that subdomain is setup with DNS provider to pass all requests to main.
DNS Record Sample:
NAME TYPE VALUE
--------------------------------------------------
exampleXYZ.com. CNAME example.com.
example.com. A 192.0.2.23
Ref:
https://en.wikipedia.org/wiki/CNAME_record
http://www.akadia.com/services/apache_redirect.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://www.iis.net/downloads/microsoft/url-rewrite
Related
We have a client that hosts their IIS web server on AWS. When navigating to a particular PHP web application on this server, it works when there is a slash on the end, but not when it is absent.
this works:
https://example.com.au/application/
However, if one were to enter this into the address bar:
https://example.com.au/application
it redirects to the equivalent http address with a slash on the end:
http://example.com.au/application/
http is disabled via the firewall, so the result is an error.
Here is the request details in Chrome debugger
So my question is, what does my client need to check to ensure this redirect does not occur? or that instead of redirecting to HTTP, it redirects to HTTPS?
Additional info:
This same issue does not seem to occur with .NET web applications. Eg 'https://example.com.au/dotnetapp' will not redirect to 'http://example.com.au/dotnetapp/'.
There are no rules configured in "URL rewrite"
IIS logs show requests when the HTTPS url is triggered, but not the HTTP one.
Edit: This seems to be due to browser caching. After disabling browser caching, i can see the 301 entry in the log files.
'index.php' is set as a default document
One possible reason is that the PHP project doesn't know that the secure connection is active and so it's redirecting the page to the http version when adding the slash.
PHP application can detect the secure connection by the $_SERVER['SERVER_PORT'], $_SERVER['REQUEST_SCHEME']. But if the application is behind some reverse proxy (e.g. Varnish or Amazon’s Elastic Load Balancer), the connection to the PHP application is probably not secured. PHP should be informed about the original secure connection with X-Forwarded-* headers.
Please check if the PHP has these variables set:
$_SERVER['HTTP_X_FORWARDED_PROTO']: should be https,
$_SERVER['HTTP_X_FORWARDED_PORT']: should be 443.
Symfony framework
If the application is using the framework, e.g. Symfony, it should be configured to trust the IP of the reverse proxy and to trust also these headers:
# config/packages/framework.yaml
framework:
# ...
# the IP address (or range) of your proxy
trusted_proxies: '192.0.0.1,10.0.0.0/8'
# trust *all* "X-Forwarded-*" headers
trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port']
# or, if your proxy instead uses the "Forwarded" header
trusted_headers: ['forwarded']
See https://symfony.com/doc/current/deployment/proxies.html for more details and https://symfony.com/doc/current/deployment/proxies.html#but-what-if-the-ip-of-my-reverse-proxy-changes-constantly for more detaiils if the IP address of reverse proxy server changes.
Looks like you are setting location header in the 'index.php' file and so browser is redirecting to the http url.
If the index.php has code like below, replace the http to https and to the correct URL
header("location:http://example.com.au/application/");
Updated :
Also check your folder to see if any other files are redirecting.
Please make sure the index.php is listed as the first in the default document list and none of the other files contain redirect code.
You can search for "meta http-equiv="refresh" http tags in all the files in folder to see if they are redirecting.
By mistake, I did not add the suffix .php when I wrote a URL into the browser during a check on my website. The browser ignored it and simply returned the page as if I had added the .php suffix, anyway! Is this normal? Do all modern browsers see a URL like www.website.com/thispage and simply go to thispage.php or thispage.html, if they exist?
Requests go to the server.
Any basic URL in the address bar of a browser make an HTTP request to the server defined by the domain (or hostname). So, http://www.something.com/here/there.x sends a whole bunch of info (in the "HEADER" of the request) to the IP registered for the www subdomain of something.com. That server gets the request, which in the header includes information about your browser, IP, type of request, the full address requested, any submitted data from a form, etc.
Your server's http engine decides what to do with it
Apache, nginx, iis, are different types of HTTP servers who's whole purpose are to listen for such requests, and decide what to do about them.
Typically, this includes setting some degree of defaults, for instance:
match the domain to a directory
something.com: /var/www/site1
strange.com: /var/www/site2
default: /var/default
match the path (everything after the '/' following the domain) to a file
check for a matching .html file
check for a matching .php file
Check permissions and authentication
Execute the file according to config
send the php file to a php process, and reroute the output
simple grab and dump the contents of images, txt, and html files.
Send a response according to what was just executed.
This is DRASTICALLY simplified, and there are many many layers and specifics, but I'm trying to keep this as simple as the question.
You tell apache (or whatever) what to do.
Apache can be configured to return a styleized google search for cats, any time anyone requests `http://blah.something.com/[anything]/*.good. It can be configured to do just about anything you want it to, based on the url you send it. The browser only decides what is sent.
It is completely up to the web server, and it's configuration, as to how a URL is handled. Web servers like Apache, NGinx, Cherokee, Litespeed, etc all have different mechanisms for what happens when a URL request hits it, and then what it decides to do afterwards.
For instance, you could have your web server attempt to add .php and .htm and .html suffixes to the requested url, in order to try to be helpful. Or simply serve up the 404 page, or send the request to the home page - eg index.php.
First Of all i want to tell that I am using XAMPP.
I have access to a folder in htdocs folder named mywebsite.
I want to wrote some sort of URL Masking Script in htaccess by which when every i visit localhost/mywebsite/index.php , content shown from another domain withour changing the URL.
I wrote below code yet but not able to do that.
RewriteEngine On
RewriteRule ^(.*)$ https://www.google.co.in/$1 [P]
It showing me
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
Kindly Clear me, Is it possible or not.
& if yes then how it will be.
If you have enabled the http servers proxy module as you confirmed in the comments to the question then you also need to enable the SSL proxy feature it offers. So I guess this is what you are looking for:
RewriteEngine On
SSLProxyEngine On
RewriteRule ^(.*)$ https://www.google.co.in/$1 [P]
If that external resource does not only consist of a single document, but has relative links, then you also need a reverse proxy, otherwise the client will break out of your proxy:
RewriteEngine On
SSLProxyEngine On
ProxyPass / https://www.google.co.in/
ProxyPassReverse / https://www.google.co.in/
However that is something you cannot do inside dynamic configuration files, you need to place such directives inside the http servers host configuration.
And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
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.
Think I have domain.com that redirects into some.otherdomain.com.
I don't want to show exact url some.otherdomain.com to my sites visitors.
I need to mask my URL, so that it will look like domain.com
Any possible way? .htaccess / javascript?
The best way to hide your domain is to use a reverse proxy (apache, nginx, ...) and provide rewrite rules to it.
Assuming domain.com and some.otherdomain.com are on two physically different servers, and you can't change the DNS information for any of them, you'll need to install a reverse proxy on domain.com. You can use mod_proxy for this. The docs are at:
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
The following information is what you need to pay attention to:
A reverse proxy, by contrast, appears to the client just like an
ordinary web server. No special configuration on the client is
necessary. The client makes ordinary requests for content in the
name-space of the reverse proxy. The reverse proxy then decides where
to send those requests, and returns the content as if it was itself
the origin.
There's an example of a reserve proxy in the docs, but you'll want something like this:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://some.otherdomain.com/
ProxyPassReverse / http://some.otherdomain.com/
Basically, any request that domains in will be proxied over to some.otherdomain.com - The local web server will forward the request over, buffer the data from otherdomain.com, then write the same data back out as if it were local data. Hope this helps!
I always think the best way is doing such things via mod_rewrite (or similar) in the server configuration (Apache or whatever is used)
On the Apache webserver of domain.com you have to enable:
mod_proxy
mod_rewrite
.htaccess
Once these requirements are completed then put this code in your .htaccess under DOCUMENT_ROOT of domain.com:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://some.otherdomain.com%{REQUEST_URI} [L,P]
Important flag here is P (Proxy) which will basically make domain.com proxy all the requests to some.otherdomain.com without showing it in the browser. See here for more documentation on this flag: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
The easier way would be to set up a page on domain.com with an iframe on it and set the source of the iframe to some.otherdomain.com. However, a user will be able to view source of the page and see that your iframe is pointing to some.otherdomain.com.
<iframe src="http://some.otherdomain.com/">...
The other option is to use a mod_rewrite in your .htaccess as shown in this thread.