snipt

Ctrl+h for KB shortcuts

Text only

Redirecting non-www to www with htaccess file

1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
https://snipt.net/embed/4b712018a1e489bfc959960f3bf85399/
/raw/4b712018a1e489bfc959960f3bf85399/
4b712018a1e489bfc959960f3bf85399
text
Text only
3
2019-07-08T23:39:18
True
False
False
/api/public/snipt/91982/
redirecting-non-www-to-www-with-htaccess-file
<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></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>RewriteCond %{HTTP_HOST} !^www\. </span><span id="L-3"><a name="L-3"></a>RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </span></pre></div> </td></tr></table>
301, htacess, redirect

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-07-15T17:19:21
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

PHP

PHP: Redirect page

1
2
3
4
5
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: howareyou.php");
exit();
?>
https://snipt.net/embed/df1029b5984d7be9e3d79c678e3e3e0a/
/raw/df1029b5984d7be9e3d79c678e3e3e0a/
df1029b5984d7be9e3d79c678e3e3e0a
php
PHP
5
2019-07-13T11:09:25
True
False
False
Jan 18, 2013 at 09:24 AM
/api/public/snipt/53971/
php-redirect-page
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">header</span><span class="p">(</span><span class="s2">&quot;HTTP/1.1 301 Moved Permanently&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Location: howareyou.php&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="k">exit</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
301, page, php, redirect

PHP

Tell the browser or bot to look for content elsewhere

1
2
3
4
5
<?php
    header("Status: 301"); # 301 Moved Permanently
    header("Location: http://prolost.com/");
    exit;
?>
https://snipt.net/embed/3c765ae0f20fade4962152e435be8070/
/raw/3c765ae0f20fade4962152e435be8070/
3c765ae0f20fade4962152e435be8070
php
PHP
5
2019-07-10T00:33:02
True
False
False
/api/public/snipt/6395/
tell-the-browser-or-bot-to-look-for-content-elsewhere
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Status: 301&quot;</span><span class="p">);</span> <span class="c1"># 301 Moved Permanently</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Location: http://prolost.com/&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">exit</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"header rewrite", "moved permanently", 301

PHP

301 Redirect

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.org"); 
https://snipt.net/embed/ad27dbe4412ce12484436db1a4afdee2/
/raw/ad27dbe4412ce12484436db1a4afdee2/
ad27dbe4412ce12484436db1a4afdee2
php
PHP
2
2019-07-14T18:02:36
True
False
False
/api/public/snipt/4199/
301-redirect-1
<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><span class="x">header(&quot;HTTP/1.1 301 Moved Permanently&quot;);</span> </span><span id="L-2"><a name="L-2"></a><span class="x">header(&quot;Location: http://www.example.org&quot;); </span> </span></pre></div> </td></tr></table>
301, php, redirect