.htaccess - Apache server config redirect from IP to domain name EC2 -
i running apache webserver on linux ec2 instance.
the problem can access server using ip address, dns , domain name. causes problem seo , want tidy up.
i have read on apache documentation can mod_rewrite , needs done in httpd.conf if have root access otherwise in .htaccess per directory override. have root access trying change httpd.conf
if user types in http://52.17.12.123/ or http://ec2-52.17.12.123.eu-west-1.compute.amazonaws.com/
i want them redirected www.example.com
this tried
<virtualhost *:80> documentroot "/var/www/html/my-website" # other directives here rewriteengine on rewritecond %{http_host} !^52.17.12.123.com$ rewriterule /* http://www.example.com/ [r] </virtualhost>
it seems partially work www.example.com not load due to many redirects.
--edit-- thanks, in httpd.conf have following configuration
listen 80 namevirtualhost *:80 documentroot "/var/www/html/my-website" rewriteengine on rewritecond %{http_host} !^(www\.example\.com)$ [nc] rewriterule ^/(.*)$ http://www.example.com [r=301,l]
it working correctly now
it seems partially work
.
doubt, considering rule have in httpd.conf
.
you can have way
rewriteengine on rewritecond %{http_host} !^www\.example\.com$ [nc] rewriterule ^/(.*)$ http://www.example.com/$1 [r=301,l]
Comments
Post a Comment