snipt

Ctrl+h for KB shortcuts

Text only

301 Redirects

1
2
3
4
5
6
Redirect a single page
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

Redirect an entire site
Redirect 301 / http://newsite.com/
https://snipt.net/embed/2551d112e14a8fbdcf7b2f6e84b5781a/
/raw/2551d112e14a8fbdcf7b2f6e84b5781a/
2551d112e14a8fbdcf7b2f6e84b5781a
text
Text only
6
2019-08-01T01:19:33
True
False
False
/api/public/snipt/80149/
301-redirects-2
<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> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>Redirect a single page </span><span id="L-2"><a name="L-2"></a>Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html </span><span id="L-3"><a name="L-3"></a>Redirect 301 /oldpage2.html http://www.yoursite.com/folder/ </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>Redirect an entire site </span><span id="L-6"><a name="L-6"></a>Redirect 301 / http://newsite.com/ </span></pre></div> </td></tr></table>
htaccess

Text only

htaccess - Redirect all traffic from old domain to new domain passing urls

RewriteEngine on 
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
https://snipt.net/embed/13ba2bde87c6921292407f3b1faf3062/
/raw/13ba2bde87c6921292407f3b1faf3062/
13ba2bde87c6921292407f3b1faf3062
text
Text only
2
2019-08-21T07:29:48
True
False
False
Jul 05, 2013 at 01:41 PM
/api/public/snipt/66541/
htaccess-redirect-all-traffic-from-old-domain-to-new-domain-passing-urls
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>RewriteEngine on </span><span id="L-2"><a name="L-2"></a>RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
301, htaccess, redirect, seo

ApacheConf

HTACCESS - Redirect Old/Missing Files to their New Versions

1
2
3
4
5
6
7
# This rule redirects any HTML files that are missing
# to the PHP version of that file
##########################################################

RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html /$1\.php [R=301,L]
https://snipt.net/embed/47cb1e8a2d6ec826afb3a100b050f340/
/raw/47cb1e8a2d6ec826afb3a100b050f340/
47cb1e8a2d6ec826afb3a100b050f340
apacheconf
ApacheConf
7
2019-08-07T09:32:08
True
False
False
/api/public/snipt/65783/
htaccess-redirect-oldmissing-files-to-their-new-versions
<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> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</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"># This rule redirects any HTML files that are missing</span> </span><span id="L-2"><a name="L-2"></a><span class="c"># to the PHP version of that file</span> </span><span id="L-3"><a name="L-3"></a><span class="c">##########################################################</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="nb">RewriteCond</span> %{REQUEST_URI} \.html$ </span><span id="L-6"><a name="L-6"></a><span class="nb">RewriteCond</span> %{REQUEST_FILENAME} !-f </span><span id="L-7"><a name="L-7"></a><span class="nb">RewriteRule</span> ^(.*)\.html /$1\.php [R=301,L] </span></pre></div> </td></tr></table>
htaccess

Java

.htaccess redirect domain with www to the one without www

1
2
3
4
5
6
# Redirect all users to access the site WITHOUT the 'www.' prefix
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteCond %{HTTP_HOST} !\.([a-z-]+\.[a-z]{2,6})$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
  
// Source: http://drupal.org/node/499104#comment-3655776
https://snipt.net/embed/43b30ec7a548bb3d4e286e1ced814f0f/
/raw/43b30ec7a548bb3d4e286e1ced814f0f/
43b30ec7a548bb3d4e286e1ced814f0f
java
Java
6
2019-08-21T06:15:37
True
False
False
/api/public/snipt/55124/
htaccess-redirect-domain-with-www-to-the-one-without-www
<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> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="err">#</span> <span class="n">Redirect</span> <span class="n">all</span> <span class="n">users</span> <span class="n">to</span> <span class="n">access</span> <span class="n">the</span> <span class="n">site</span> <span class="n">WITHOUT</span> <span class="n">the</span> <span class="err">&#39;</span><span class="n">www</span><span class="o">.</span><span class="err">&#39;</span> <span class="n">prefix</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">RewriteCond</span> <span class="o">%{</span><span class="n">HTTP_HOST</span><span class="o">}</span> <span class="o">^</span><span class="n">www</span><span class="err">\</span><span class="o">.(.+)</span><span class="n">$</span> <span class="o">[</span><span class="n">NC</span><span class="o">]</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">RewriteCond</span> <span class="o">%{</span><span class="n">HTTP_HOST</span><span class="o">}</span> <span class="o">!</span><span class="err">\</span><span class="o">.([</span><span class="n">a</span><span class="o">-</span><span class="n">z</span><span class="o">-]+</span><span class="err">\</span><span class="o">.[</span><span class="n">a</span><span class="o">-</span><span class="n">z</span><span class="o">]{</span><span class="mi">2</span><span class="o">,</span><span class="mi">6</span><span class="o">})</span><span class="n">$</span> <span class="o">[</span><span class="n">NC</span><span class="o">]</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">RewriteRule</span> <span class="o">^</span> <span class="n">http</span><span class="o">:</span><span class="c1">//%1%{REQUEST_URI} [L,R=301]</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">// Source: http://drupal.org/node/499104#comment-3655776</span> </span></pre></div> </td></tr></table>
config, htaccess, server