: Remove IP address from the URL of website using apache I'm on an EC2 instance and have a domain domain.com linked to the EC2 nameservers and it happily is serving my pages if I type domain.com
I'm on an EC2 instance and have a domain domain.com linked to the EC2 nameservers and it happily is serving my pages if I type domain.com in the URL.
However when the page is served it resolves the url to: 1.1.1.10/directory/page.php.
Using apache I've set up the following VirtualHost, following examples provided at httpd.apache.org/docs/2.0/dns-caveats.html
Listen 80
NameVirtualHost 1.1.1.10:80
<VirtualHost 1.1.1.10:80>
DocumentRoot /var/www/html/directory
ServerName domain.com
# Other directives here ...
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
</VirtualHost>
However I'm not getting any changes to how the URL is displayed.
This is the only VirtualHost configured on this site and I've confirmed its the one being used as I've managed to break it a number of times whilst experimenting with the configuration.
The route53 entries I have are:
domain.com A 1.1.1.10
domain.com NS ns-11.awsdns-11.com
ns-111.awsdns-11.net
ns-1111.awsdns-11.org
ns-1111.awsdns-11.co.uk
domain.com SOA ns-11.awsdns-11.com. awsdns-hostmaster.amazon.com. 1 1100 100 1101100 11100
More posts by @Gonzalez347
2 Comments
Sorted by latest first Latest Oldest Best
First, use <VirtualHost *:80> instead of <VirtualHost 1.1.1.10:80>. That way your virtual host applies no matter what the IP address of your server is.
Second, you need to issue a redirect if the host name isn't what you expect. I would recommend having two virtual hosts. The first is the default one for any unexpected domain names or IP addresses. It can issue a redirect to the correct domain name. The second one should be the one for your domain name. Something like:
<VirtualHost *:80>
ServerName localhost.localdomain
Redirect permanent / domain.com/ </VirtualHost>
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www/html/directory
# Other directives here ...
</VirtualHost>
You'll need to set up a DNS record on the server - an A record using the IP address as the destination/target.
As an example, in your VirtualHost file, you should have something like:-
<VirtualHost *:80>
ServerName domain.com ServerAlias domain.com
DocumentRoot "/var/websites/domain/"
ErrorLog "/var/websites/domain/logs/error.log"
CustomLog "/var/websites/domain/logs/access.log"
</VirtualHost>
Obviously the above needs amending to the relevant paths on your server accordingly based on how you have it set up (you may need to create the necessary directories if they don't already exist).
Then you'd need to restart the server with service httpd restartfor the changes to take affect. Whether this differs on an EC2 instance I'm unsure, but this is what is needed on an Apache server.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.