Originally Posted by SteveZ23
Okay, so I have this I am assume this is wrong for the most part but that is what I found when it comes to creating redirects
this is inside my /etc/nttpd/conf/httpd.conf
# ServerAdmin email@example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
RedirectMatch permanent ^/(.*) http://google.com/$1
Firstly, you're best off posting apache configs inside [ code ] tags as Huddler, being the dumbest of all the forum softwares, tries to turn Apache's XML-like config into HTML tags.
Now with regards to the config itself, there's two ways to do vhosts, using IP address and using names. With IP addresses, you'd set the IP in the <VirtualHost :80> bit. eg
So that the IP 184.108.40.206
is binded to a different vhost to 220.127.116.11
However since your CentOS install likely only has one WAN IP, you're batter off using named servers - which I can see you attempted at. Where you went wrong is you used an IP instead of a server name:
What this does is all IPs are binded to all vhosts, but Apache will decide which vhost to run depending on what the hostname is set in your HTTP request. This is where I have to explain a little about how HTTP works.
When your web browser (be that Firefox, IE, Chrome or even command line tools like curl
- all HTTP requests send the same basic header information) requests a webpage, the following text is transmitted from your browser to the web server (Apache on CentOS in this example):
GET /index.html HTTP/1.1
What that request says is get
the webpage index.html
from a vhost called www.example.com
. The Host
line is not
a DNS look up - that's already done before this stage because otherwise your browser wouldn't be able to connect to the web server to send this message. So it's literally just telling the web server which virtual host you want to view. If you're using IP based vhosts in Apache, then the host field is ignored since there's only one vhost on that IP and you know what IP you're requesting on since you're already connected on it to send that HTTP request. However if you're using named based hosts, then you'll have several vhosts per IP - and that's when the Host
In your case, you're using named based hosts, so you need to not only have Apache set up with config akin to my 2nd vhost example, but you also need to configure your webbrowser to send a request where the Host
field is correct - thats the complicated bit.
This where the hosts file and DNS part your boss discussed comes into play. Apache doesn't actually need anything in the hosts file to work (with some configurations, Apache may throw a warning up - but generally you don't need
to edit your hosts file to configure Apache). However since you're not using DNS, you need some way to test your Apache config, and this
is where the hosts file comes into play. You only need to change the hosts file on whatever computer your HTTP request is originating from. eg if you're testing your CentOS box from Firefox on your Windows desktop, then you need to set your windows hosts file (IIRC located at %windir%\system\drivers\etc\hosts) to point yahoo.example.com and google.example.com to your CentOS box. If you want to test Apache from CentOS (eg using a command line client like lynx
) then you need to set the /etc/hosts file in CentOS.
In the mean time, there is a command line way of forcing an entry in the Host
curl -IH "google.example.com" localhost
Run that on your CentOS box and you'll get HTTP headers return from Apache which will say something like:
HTTP/1.1 301 Moved Permanently
....extra lines of data....
if the redirect works (if you're not familiar with what HTTP/1.1 301
means, it's just saying HTTP protocol, version 1.1, HTTP status code 301. The 301 is the important bit and it's worth Googling "HTTP status codes" to find out more if you get stuck as that's Apache telling you how successful your HTTP request was - which in turn can highlight if there is errors in your HTTP config, errors in your server side code, or even errors with your HTTP request).
Lastly, the impression I've got is that this CentOS box is hosted externally (ie with any one of the popular Linux VPS providers). If that's the case, then I would double check your WAN IP because the IPs you've posted in this thread (the ones starting with 192.) are not WAN IPs. So if you're connecting to this box over the internet, then you need to double check which IP you're using in your Apache config.
Hope this all helps