snipt

Ctrl+h for KB shortcuts

PHP

.htaccess user agent sniffing for iPhone

1
2
3
4
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/_mobile/
RewriteRule .* /_mobile/ [R]
https://snipt.net/embed/924e799b615353a102639dfd6944f73d/
/raw/924e799b615353a102639dfd6944f73d/
924e799b615353a102639dfd6944f73d
php
PHP
4
2019-06-21T15:37:38
True
False
False
/api/public/snipt/15398/
htaccess-user-agent-sniffing-for-iphone
<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="x">RewriteEngine on</span> </span><span id="L-2"><a name="L-2"></a><span class="x">RewriteCond %{HTTP_USER_AGENT} iPhone</span> </span><span id="L-3"><a name="L-3"></a><span class="x">RewriteCond %{REQUEST_URI} !^/_mobile/</span> </span><span id="L-4"><a name="L-4"></a><span class="x">RewriteRule .* /_mobile/ [R]</span> </span></pre></div> </td></tr></table>
htaccess

Text only

code added to .htaccess to enable compression of certain served content using Apache mod_deflate

# compress all text & html
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/css application/x-javascript application/javascript
https://snipt.net/embed/00eeb47352ae3f9782f4de7d88b1406c/
/raw/00eeb47352ae3f9782f4de7d88b1406c/
00eeb47352ae3f9782f4de7d88b1406c
text
Text only
2
2019-07-15T10:41:24
True
False
False
/api/public/snipt/14175/
code-added-to-htaccess-to-enable-compression-of-certain-served-content-using-apache-mod_deflate
<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># compress all text &amp; html </span><span id="L-2"><a name="L-2"></a>AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/css application/x-javascript application/javascript </span></pre></div> </td></tr></table>
apache, compress, compression, htaccess, mod_deflate

Bash

htaccess redirect all traffic to homepage

1
2
3
4
5
6
7
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . http://domain.tld/index.php [L]
</IfModule>
https://snipt.net/embed/1b935b82b54ddc05b79fa76309ba9795/
/raw/1b935b82b54ddc05b79fa76309ba9795/
1b935b82b54ddc05b79fa76309ba9795
bash
Bash
7
2019-07-09T03:14:12
True
False
False
/api/public/snipt/12024/
htaccess-redirect-all-traffic-to-homepage
<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>&lt;IfModule mod_rewrite.c&gt; </span><span id="L-2"><a name="L-2"></a>RewriteEngine On </span><span id="L-3"><a name="L-3"></a>RewriteBase / </span><span id="L-4"><a name="L-4"></a>RewriteCond %<span class="o">{</span>REQUEST_FILENAME<span class="o">}</span> !-f </span><span id="L-5"><a name="L-5"></a>RewriteCond %<span class="o">{</span>REQUEST_FILENAME<span class="o">}</span> !-d </span><span id="L-6"><a name="L-6"></a>RewriteRule . http://domain.tld/index.php <span class="o">[</span>L<span class="o">]</span> </span><span id="L-7"><a name="L-7"></a>&lt;/IfModule&gt; </span></pre></div> </td></tr></table>
apache, htaccess, server, traffic

Bash

mod_rewrite to fix blogger moving

1
2
3
4
5
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/blog/images/(.*)$ [NC]
RewriteCond %{REQUEST_URI} ^/blog/(.*)$ [NC]
RewriteRule ^blog/(.*)$ http://blog.domain.com/$1 [R=301,L]
https://snipt.net/embed/436bdcc59ca1898bea1ecf70180f99b2/
/raw/436bdcc59ca1898bea1ecf70180f99b2/
436bdcc59ca1898bea1ecf70180f99b2
bash
Bash
6
2019-07-11T04:32:45
True
False
False
/api/public/snipt/11962/
mod_rewrite-to-fix-blogger-moving
<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>RewriteEngine On </span><span id="L-2"><a name="L-2"></a>RewriteBase / </span><span id="L-3"><a name="L-3"></a>RewriteCond %<span class="o">{</span>REQUEST_URI<span class="o">}</span> !^/blog/images/<span class="o">(</span>.*<span class="o">)</span>$ <span class="o">[</span>NC<span class="o">]</span> </span><span id="L-4"><a name="L-4"></a>RewriteCond %<span class="o">{</span>REQUEST_URI<span class="o">}</span> ^/blog/<span class="o">(</span>.*<span class="o">)</span>$ <span class="o">[</span>NC<span class="o">]</span> </span><span id="L-5"><a name="L-5"></a>RewriteRule ^blog/<span class="o">(</span>.*<span class="o">)</span>$ http://blog.domain.com/<span class="nv">$1</span> <span class="o">[</span><span class="nv">R</span><span class="o">=</span>301,L<span class="o">]</span> </span></pre></div> </td></tr></table>
htaccess, mod, rewrite

ApacheConf

301 redirect - non-www to www

1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
https://snipt.net/embed/83597c4eedd7120439d289375466c5ad/
/raw/83597c4eedd7120439d289375466c5ad/
83597c4eedd7120439d289375466c5ad
apacheconf
ApacheConf
3
2019-07-13T13:07:01
True
False
False
/api/public/snipt/10114/
301-redirect-non-www-to-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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nb">RewriteEngine</span> <span class="k">On</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">RewriteCond</span> %{HTTP_HOST} ^example.com </span><span id="L-3"><a name="L-3"></a><span class="nb">RewriteRule</span> (.*) http://www.example.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
"301 redirect", apache, htaccess