Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Force all Upper Case URL's to lower case and redirect to lowercase

1
2
3
4
5
6
## Rewrite all MiXed Case uRLs to lower case URL's and 301 redirect in one elegant statement ##

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
https://snipt.net/embed/8beaa95d007c906e725f2c302ecd7922/
https://snipt.net/raw/8beaa95d007c906e725f2c302ecd7922/
8beaa95d007c906e725f2c302ecd7922
text
Text only
7
2016-12-04T21:06:54
True
False
False
/api/public/snipt/12951/
force-all-upper-case-urls-to-lower-case-and-redirect-to-lowercase
<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>## Rewrite all MiXed Case uRLs to lower case URL&#39;s and 301 redirect in one elegant statement ## </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>RewriteEngine On </span><span id="L-4"><a name="L-4"></a>RewriteMap lc int:tolower </span><span id="L-5"><a name="L-5"></a>RewriteCond %{REQUEST_URI} [A-Z] </span><span id="L-6"><a name="L-6"></a>RewriteRule (.*) ${lc:$1} [R=301,L] </span></pre></div> </td></tr></table>
mod_rewrite, seo, url

Text only

Remove Folders from URLs

1
2
3
4
5
6
## Remove a subfolder from a URL ##

Options +FollowSymLinks
RewriteEngine On
RewriteBase /sports
RewriteCond ^sports/(.*)$ /$1 [L] 
https://snipt.net/embed/1223b14910430a64cccc9741c3d7476b/
https://snipt.net/raw/1223b14910430a64cccc9741c3d7476b/
1223b14910430a64cccc9741c3d7476b
text
Text only
6
2016-12-04T09:03:24
True
False
False
/api/public/snipt/12948/
remove-folders-from-urls
<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>## Remove a subfolder from a URL ## </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>Options +FollowSymLinks </span><span id="L-4"><a name="L-4"></a>RewriteEngine On </span><span id="L-5"><a name="L-5"></a>RewriteBase /sports </span><span id="L-6"><a name="L-6"></a>RewriteCond ^sports/(.*)$ /$1 [L] </span></pre></div> </td></tr></table>
"seo rewrite", folder, mod_rewrite, url

Text only

Redirects domain.com/5 to domain.com/event.php?id=5

1
2
3
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)?$ /page.php?id=$1 [NC,L] 
https://snipt.net/embed/1cb29dcaaefa8eea73052ce14e67baef/
https://snipt.net/raw/1cb29dcaaefa8eea73052ce14e67baef/
1cb29dcaaefa8eea73052ce14e67baef
text
Text only
3
2016-12-02T00:35:30
True
False
False
/api/public/snipt/7307/
redirects-domaincom5-to-domaincomeventphpid5
<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>Options +FollowSymLinks </span><span id="L-2"><a name="L-2"></a>RewriteEngine On </span><span id="L-3"><a name="L-3"></a>RewriteRule ^([A-Za-z0-9-]+)?$ /page.php?id=$1 [NC,L] </span></pre></div> </td></tr></table>
"force page", .htaccess, mod_rewrite

Text only

.htaccess to force https://www.* -- works with subdomains as well

1
2
3
4
5
6
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301]

RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
https://snipt.net/embed/ed8a60038cd1610054ee7538205034ac/
https://snipt.net/raw/ed8a60038cd1610054ee7538205034ac/
ed8a60038cd1610054ee7538205034ac
text
Text only
6
2016-12-05T04:27:44
True
False
False
/api/public/snipt/7209/
htaccess-to-force-httpswww-works-with-subdomains-as-well
<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>RewriteEngine On </span><span id="L-2"><a name="L-2"></a>RewriteCond %{HTTP_HOST} ^domain.com$ </span><span id="L-3"><a name="L-3"></a>RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301] </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>RewriteCond %{HTTP_HOST} ^www.domain.com$ </span><span id="L-6"><a name="L-6"></a>RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
.htaccess, https, mod_rewrite, ssl

Bash

Redirects traffic to local SSL

1
2
3
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
https://snipt.net/embed/8ebecf707aac4567b7719a46897d3449/
https://snipt.net/raw/8ebecf707aac4567b7719a46897d3449/
8ebecf707aac4567b7719a46897d3449
bash
Bash
3
2016-12-02T00:34:53
True
False
False
/api/public/snipt/6712/
redirects-traffic-to-local-ssl
<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 %<span class="o">{</span>HTTPS<span class="o">}</span> off </span><span id="L-3"><a name="L-3"></a>RewriteRule <span class="o">(</span>.*<span class="o">)</span> https://%<span class="o">{</span>HTTP_HOST<span class="o">}</span>%<span class="o">{</span>REQUEST_URI<span class="o">}</span> </span></pre></div> </td></tr></table>
.htaccess, mod_rewrite, redirect, ssl

ApacheConf

debug apache variables

RewriteCond %{QUERY_STRING} !vardump 
RewriteRule (.*) http://localhost/debug.php?vardump&HTTP_USER_AGENT=%{HTTP_USER_AGENT}&HTTP_REFERER=%{HTTP_REFERER}&HTTP_COOKIE=%{HTTP_COOKIE}&HTTP_FORWARDED=%{HTTP_FORWARDED}&HTTP_HOST=%{HTTP_HOST}&HTTP_PROXY_CONNECTION=%{HTTP_PROXY_CONNECTION}&HTTP_ACCEPT=%{HTTP_ACCEPT}&DOCUMENT_ROOT=%{DOCUMENT_ROOT}&SERVER_ADMIN=%{SERVER_ADMIN}&SERVER_NAME=%{SERVER_NAME}&SERVER_ADDR=%{SERVER_ADDR}&SERVER_PORT=%{SERVER_PORT}&SERVER_PROTOCOL=%{SERVER_PROTOCOL}&SERVER_SOFTWARE=%{SERVER_SOFTWARE}&REMOTE_ADDR=%{REMOTE_ADDR}&REMOTE_HOST=%{REMOTE_HOST}&REMOTE_PORT=%{REMOTE_PORT}&REMOTE_USER=%{REMOTE_USER}&REMOTE_IDENT=%{REMOTE_IDENT}&REQUEST_METHOD=%{REQUEST_METHOD}&SCRIPT_FILENAME=%{SCRIPT_FILENAME}&PATH_INFO=%{PATH_INFO}&QUERY_STRING=%{QUERY_STRING}&AUTH_TYPE=%{AUTH_TYPE}&TIME_YEAR=%{TIME_YEAR}&TIME_MON=%{TIME_MON}&TIME_DAY=%{TIME_DAY}&TIME_HOUR=%{TIME_HOUR}&TIME_MIN=%{TIME_MIN}&TIME_SEC=%{TIME_SEC}&TIME_WDAY=%{TIME_WDAY}&TIME=%{TIME}&API_VERSION=%{API_VERSION}&THE_REQUEST=%{THE_REQUEST}&REQUEST_URI=%{REQUEST_URI}&REQUEST_FILENAME=%{REQUEST_FILENAME}&IS_SUBREQ=%{IS_SUBREQ}&HTTPS=%{HTTPS} [R=302,L,QSA] 
https://snipt.net/embed/f4b1f5b7bf044b5d778459204bd941dd/
https://snipt.net/raw/f4b1f5b7bf044b5d778459204bd941dd/
f4b1f5b7bf044b5d778459204bd941dd
apacheconf
ApacheConf
2
2016-12-04T22:35:49
True
False
False
/api/public/snipt/4648/
debug-apache-variables
<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="nb">RewriteCond</span> %{QUERY_STRING} !vardump </span><span id="L-2"><a name="L-2"></a><span class="nb">RewriteRule</span> (.*) http://localhost/debug.php?vardump&amp;HTTP_USER_AGENT=%{HTTP_USER_AGENT}&amp;HTTP_REFERER=%{HTTP_REFERER}&amp;HTTP_COOKIE=%{HTTP_COOKIE}&amp;HTTP_FORWARDED=%{HTTP_FORWARDED}&amp;HTTP_HOST=%{HTTP_HOST}&amp;HTTP_PROXY_CONNECTION=%{HTTP_PROXY_CONNECTION}&amp;HTTP_ACCEPT=%{HTTP_ACCEPT}&amp;DOCUMENT_ROOT=%{DOCUMENT_ROOT}&amp;SERVER_ADMIN=%{SERVER_ADMIN}&amp;SERVER_NAME=%{SERVER_NAME}&amp;SERVER_ADDR=%{SERVER_ADDR}&amp;SERVER_PORT=%{SERVER_PORT}&amp;SERVER_PROTOCOL=%{SERVER_PROTOCOL}&amp;SERVER_SOFTWARE=%{SERVER_SOFTWARE}&amp;REMOTE_ADDR=%{REMOTE_ADDR}&amp;REMOTE_HOST=%{REMOTE_HOST}&amp;REMOTE_PORT=%{REMOTE_PORT}&amp;REMOTE_USER=%{REMOTE_USER}&amp;REMOTE_IDENT=%{REMOTE_IDENT}&amp;REQUEST_METHOD=%{REQUEST_METHOD}&amp;SCRIPT_FILENAME=%{SCRIPT_FILENAME}&amp;PATH_INFO=%{PATH_INFO}&amp;QUERY_STRING=%{QUERY_STRING}&amp;AUTH_TYPE=%{AUTH_TYPE}&amp;TIME_YEAR=%{TIME_YEAR}&amp;TIME_MON=%{TIME_MON}&amp;TIME_DAY=%{TIME_DAY}&amp;TIME_HOUR=%{TIME_HOUR}&amp;TIME_MIN=%{TIME_MIN}&amp;TIME_SEC=%{TIME_SEC}&amp;TIME_WDAY=%{TIME_WDAY}&amp;TIME=%{TIME}&amp;API_VERSION=%{API_VERSION}&amp;THE_REQUEST=%{THE_REQUEST}&amp;REQUEST_URI=%{REQUEST_URI}&amp;REQUEST_FILENAME=%{REQUEST_FILENAME}&amp;IS_SUBREQ=%{IS_SUBREQ}&amp;HTTPS=%{HTTPS} [R=302,L,QSA] </span></pre></div> </td></tr></table>
apache, debug, mod_rewrite, variables

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/
https://snipt.net/raw/e0c21793a83cfd9c295fb51f2dad4dba/
e0c21793a83cfd9c295fb51f2dad4dba
apacheconf
ApacheConf
4
2016-12-01T11:11:00
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

ApacheConf

mod_rewrite 301 redirect

RewriteRule ^whatever/(.*)$ http://www.domain.com/$1/ [R=301,L]
https://snipt.net/embed/e4754a4e77c65133b1c9404bb821e45a/
https://snipt.net/raw/e4754a4e77c65133b1c9404bb821e45a/
e4754a4e77c65133b1c9404bb821e45a
apacheconf
ApacheConf
1
2016-12-05T04:05:56
True
False
False
/api/public/snipt/438/
mod_rewrite-301-redirect
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nb">RewriteRule</span> ^whatever/(.*)$ http://www.domain.com/$1/ [R=301,L] </span></pre></div> </td></tr></table>
apache, mod_rewrite
Copyrighted, illegal, or inappropriate content? Email [email protected].