apache - Redirect www to naked domain -
apache - Redirect www to naked domain -
i'm trying redirect of website traffic naked domain (looks much cleaner in opinion), when googling found lot of different methods going it. utilize cloudflare's free ssl, i'd solution works both , without ssl (in case happens , disable ssl or whatever), , i'd preferably globally (i.e. without .htaccess file). in case matters, apache 2.4.10 on ubuntu server 14.10.
i found this article, placing code (below) virtualhost directive gave error below. apache error log doesn't have useful. can prepare problem , create redirect works properly? (if should doing other way i'm open well; have access command dns settings , whatnot if needed.)
code inserted apache2/sites-available/000-default.conf:
rewriteengine on rewritecond %{https} off rewritecond %{http_host} !^www\.(.*)$ [nc] rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] rewritecond %{https} on rewritecond %{http_host} !^www\.(.*)$ [nc] rewriterule ^(.*)$ https://www.%{http_host}/$1 [r=301,l] error code receive when restarting apache:
* apache2 configtest failed. output of config test was: ah00526: syntax error on line 30 of /etc/apache2/sites-enabled/000-default.conf: invalid command 'rewriteengine', perhaps misspelled or defined module not included in server configuration action 'configtest' failed. apache error log may have more information.
the rewrite module not enabled default.
enable rewrite module:
sudo a2enmod rewrite
change 000-default.conf to
rewritecond %{https} on rewritecond %{http_host} ^www\.(.+)$ [nc] rewriterule ^(.*)$ https://%1/$1 [r=301,l] rewritecond %{http_host} ^www\.(.+)$ [nc] rewriterule ^(.*)$ http://%1/$1 [r=301,l] then
sudo service apache2 restart apache redirect ssl ubuntu-server
Comments
Post a Comment