snipt

Ctrl+h for KB shortcuts

ApacheConf

redirect www traffic to non-www domain dynamically with multiple domains in same virtualhost

1
2
3
4
# Redirect www to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [L,R=301]
https://snipt.net/embed/e0c21793a83cfd9c295fb51f2dad4dba/
/raw/e0c21793a83cfd9c295fb51f2dad4dba/
e0c21793a83cfd9c295fb51f2dad4dba
apacheconf
ApacheConf
4
2019-06-11T18:34:51
True
False
False
/api/public/snipt/2588/
redirect-www-traffic-to-non-www-domain-dynamically-with-multiple-domains-in-same-virtualhost
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c"># Redirect www to non-www</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">RewriteEngine</span> <span class="k">on</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">RewriteCond</span> %{HTTP_HOST} ^www\.(.+)$ [NC] </span><span id="L-4"><a name="L-4"></a><span class="nb">RewriteRule</span> ^(.*)$ http://%1$1 [L,R=301] </span></pre></div> </td></tr></table>
apache, mod_rewrite, virtualhost