0

Inside virtuahost apache conf file /etc/apache2/sites-available/000-default.conf

I tried to put these code inside apache conf file

ServerName example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]

also I tried,

< If "%{HTTP_HOST} != 'YOUR-DOMAIN.com'">
Redirect "/" "http://www.YOUR-DOMAIN.com/"
</If>

also did this

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.com
    # real server configuration
</VirtualHost>
HBruijn
  • 72,524
  • 21
  • 127
  • 192
Mark178
  • 11
  • 1
  • 6

1 Answers1

0

Your last code block should have worked 100%.

As @HBrujin commented this looks like a cache fault from an initial redirect error.

I suggest you try using Google Chrome with networking tools which allow you to load a page with all caches disabled.

Simply inspect your page and navigate to Networking tab. Check the disable cache checkbox and reload your page with the 3d code block of yours. It should work.

You can check this article as well on how to clear your cache from all browsers.

1337_sanc
  • 111
  • 1
  • 6
  • I cleared all browser cache also tried in different device and still the same. – Mark178 Jan 05 '18 at 15:13
  • Any chance you could share some logs from apache access log? They could be find found on `/var/log/apache2/access.log` or `/var/log/httpd/access.log` if you set it up via a package manager. make sure you change domain names and ips. Also try to tail -f the .log and see what redirects are going on the momment you access the domain. – 1337_sanc Jan 05 '18 at 16:11
  • I don't know to use -f and .log, I a newbie. I checked logs at /var/log/apache2/access.log and there were no errors but only things such as google bot crawling website. – Mark178 Jan 05 '18 at 16:38
  • What were the exact lines for your testing attempts in the log? Edit those lines in the original question. – Tero Kilkanen Jan 06 '18 at 12:39