snipt

Ctrl+h for KB shortcuts

Text only

.htaccess: Prevent website directory listing 1

Options -Indexes
https://snipt.net/embed/aaf2d87bdaf511f2cc54905f9701ed8d/
/raw/aaf2d87bdaf511f2cc54905f9701ed8d/
aaf2d87bdaf511f2cc54905f9701ed8d
text
Text only
2
2019-08-23T19:21:48
True
False
False
/api/public/snipt/54285/
htaccess-prevent-website-directory-listing
<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>Options -Indexes </span></pre></div> </td></tr></table>
directory, htaccess, listing

ApacheConf

HTACCESS - Go Away

1
2
3
4
5
# Send that bastard right back where he came from
###################################################

RewriteEngine On
RewriteRule (.*) %{HTTP_REFERER} [R=301,L]
https://snipt.net/embed/16210f16cd24415830ad19b4a481c388/
/raw/16210f16cd24415830ad19b4a481c388/
16210f16cd24415830ad19b4a481c388
apacheconf
ApacheConf
5
2019-08-16T11:09:48
True
False
False
/api/public/snipt/53716/
htaccess-go-away
<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="c"># Send that bastard right back where he came from</span> </span><span id="L-2"><a name="L-2"></a><span class="c">###################################################</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nb">RewriteEngine</span> <span class="k">On</span> </span><span id="L-5"><a name="L-5"></a><span class="nb">RewriteRule</span> (.*) %{HTTP_REFERER} [R=301,L] </span></pre></div> </td></tr></table>
htaccess

Text only

.htaccess: Protect site from Hotlinking

1
2
3
4
5
6
7
RewriteEngine on
 
RewriteCond %{HTTP_REFERER} !^$
 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
https://snipt.net/embed/98cca817622c77e99190eed437730890/
/raw/98cca817622c77e99190eed437730890/
98cca817622c77e99190eed437730890
text
Text only
7
2019-08-24T21:48:56
True
False
False
/api/public/snipt/53005/
htaccess-protect-site-from-hotlinking
<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>RewriteEngine on </span><span id="L-2"><a name="L-2"></a>  </span><span id="L-3"><a name="L-3"></a>RewriteCond %{HTTP_REFERER} !^$ </span><span id="L-4"><a name="L-4"></a>  </span><span id="L-5"><a name="L-5"></a>RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC] </span><span id="L-6"><a name="L-6"></a>  </span><span id="L-7"><a name="L-7"></a>RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] </span></pre></div> </td></tr></table>
hotlinking, htaccess, protection

Text only

.htaccess: Blocking access from everyone but one IP

1
2
3
order deny,allow 
deny from all 
allow from xxx.xxx.xxx.xxx
https://snipt.net/embed/f582420136e1d485d17ad7a038d82649/
/raw/f582420136e1d485d17ad7a038d82649/
f582420136e1d485d17ad7a038d82649
text
Text only
3
2019-08-17T11:54:08
True
False
False
/api/public/snipt/53004/
htaccess-blocking-access-from-everyone-but-one-ip
<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>order deny,allow </span><span id="L-2"><a name="L-2"></a>deny from all </span><span id="L-3"><a name="L-3"></a>allow from xxx.xxx.xxx.xxx </span></pre></div> </td></tr></table>
IP, block, htaccess

Text only

.htaccess: Redirection to mainenance page

1
2
3
4
5
6
# Redirection to the Maintenance Page
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^99\.142\.141\.42
RewriteCond %{REQUEST_URI} !/maintenance.htm$
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif)
RewriteRule .* /maintenance.htm [R=307,L]
https://snipt.net/embed/f8162423222c07639688899a2efe6e73/
/raw/f8162423222c07639688899a2efe6e73/
f8162423222c07639688899a2efe6e73
text
Text only
6
2019-08-23T17:10:44
True
False
False
Jan 09, 2013 at 02:33 AM
/api/public/snipt/52991/
htaccess-redirection-to-mainenance-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> <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># Redirection to the Maintenance Page </span><span id="L-2"><a name="L-2"></a>RewriteEngine on </span><span id="L-3"><a name="L-3"></a>RewriteCond %{REMOTE_ADDR} !^99\.142\.141\.42 </span><span id="L-4"><a name="L-4"></a>RewriteCond %{REQUEST_URI} !/maintenance.htm$ </span><span id="L-5"><a name="L-5"></a>RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif) </span><span id="L-6"><a name="L-6"></a>RewriteRule .* /maintenance.htm [R=307,L] </span></pre></div> </td></tr></table>
"maintenance page", htaccess

Text only

Ejecutar un PHP en vez de un JS

1
2
3
4
5
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/magic.js
RewriteCond %{QUERY_STRING} ((.*))?
RewriteRule (.*)  magic.php?%2 [L]
https://snipt.net/embed/47146a4e3fbda964500551cfd323c087/
/raw/47146a4e3fbda964500551cfd323c087/
47146a4e3fbda964500551cfd323c087
text
Text only
5
2019-08-22T22:54:49
True
False
False
/api/public/snipt/52883/
ejecutar-un-php-en-vez-de-un-js
<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> </span><span id="L-3"><a name="L-3"></a>RewriteCond %{REQUEST_URI} ^/magic.js </span><span id="L-4"><a name="L-4"></a>RewriteCond %{QUERY_STRING} ((.*))? </span><span id="L-5"><a name="L-5"></a>RewriteRule (.*) magic.php?%2 [L] </span></pre></div> </td></tr></table>
apache, htaccess, js, php, vhost

Perl

htacess - force PDF download

1
2
3
4
5
## Force PDF download.
<FilesMatch "\.(pdf|PDF)">
  ForceType application/pdf
  Header set Content-Disposition attachment
</FilesMatch>
https://snipt.net/embed/b19d8abd6d4781b9755e5e04dfcb05bc/
/raw/b19d8abd6d4781b9755e5e04dfcb05bc/
b19d8abd6d4781b9755e5e04dfcb05bc
perl
Perl
5
2019-08-20T06:39:13
True
False
False
Dec 28, 2012 at 03:18 AM
/api/public/snipt/52456/
htacess-force-pdf-download
<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="c1">## Force PDF download.</span> </span><span id="L-2"><a name="L-2"></a><span class="o">&lt;</span><span class="n">FilesMatch</span> <span class="s">&quot;\.(pdf|PDF)&quot;</span><span class="o">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">ForceType</span> <span class="n">application</span><span class="o">/</span><span class="n">pdf</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">Header</span> <span class="n">set</span> <span class="n">Content</span><span class="o">-</span><span class="n">Disposition</span> <span class="n">attachment</span> </span><span id="L-5"><a name="L-5"></a><span class="sr">&lt;/FilesMatch&gt;</span> </span></pre></div> </td></tr></table>
download, htaccess, pdf

ApacheConf

Fix @Font-Face access issue, in Firefox

1
2
3
4
5
<FilesMatch "\.(ttf|otf|eot)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>
https://snipt.net/embed/f9e42136007d531f91dfed087dd89263/
/raw/f9e42136007d531f91dfed087dd89263/
f9e42136007d531f91dfed087dd89263
apacheconf
ApacheConf
5
2019-08-16T12:09:14
True
False
False
/api/public/snipt/49740/
fix-font-face-access-issue-in-firefox
<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="nt">&lt;FilesMatch</span> <span class="s">&quot;\.(ttf|otf|eot)$&quot;</span><span class="nt">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">&lt;IfModule</span> <span class="s">mod_headers.c</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">Header</span> set Access-Control-Allow-Origin <span class="s2">&quot;*&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nt">&lt;/IfModule&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">&lt;/FilesMatch&gt;</span> </span></pre></div> </td></tr></table>
htaccess

ApacheConf

Redirect with Optional Character

1
2
3
4
5
6
# Will redirect both, with or without the "s"
# http://domain.com/service_math-tutoring.html
# http://domain.com/services_math-tutoring.html
#####################################################

RewriteRule ^service(|s)_math-tutoring\.html$ /math_tutoring.html [R=301,L]
https://snipt.net/embed/c892fd3602d9efed8e29fc705876c30f/
/raw/c892fd3602d9efed8e29fc705876c30f/
c892fd3602d9efed8e29fc705876c30f
apacheconf
ApacheConf
6
2019-08-15T06:29:32
True
False
False
Nov 06, 2012 at 01:38 PM
/api/public/snipt/49739/
redirect-with-optional-character
<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="c"># Will redirect both, with or without the &quot;s&quot;</span> </span><span id="L-2"><a name="L-2"></a><span class="c"># http://domain.com/service_math-tutoring.html</span> </span><span id="L-3"><a name="L-3"></a><span class="c"># http://domain.com/services_math-tutoring.html</span> </span><span id="L-4"><a name="L-4"></a><span class="c">#####################################################</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="nb">RewriteRule</span> ^service(|s)_math-tutoring\.html$ <span class="sx">/math_tutoring.html</span> [R=301,L] </span></pre></div> </td></tr></table>
htaccess

XML

.htaccess fontface

1
2
3
4
5
<FilesMatch "\.(ttf|otf|eot|woff)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>
https://snipt.net/embed/71991f26beaa2d56725530db0a21dc0f/
/raw/71991f26beaa2d56725530db0a21dc0f/
71991f26beaa2d56725530db0a21dc0f
xml
XML
5
2019-08-17T16:15:18
True
False
False
Oct 05, 2012 at 11:13 AM
/api/public/snipt/48124/
htaccess-fontface
<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="nt">&lt;FilesMatch</span> <span class="err">&quot;\.(ttf|otf|eot|woff)$&quot;</span><span class="nt">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">&lt;IfModule</span> <span class="err">mod_headers.c</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> Header set Access-Control-Allow-Origin &quot;*&quot; </span><span id="L-4"><a name="L-4"></a> <span class="nt">&lt;/IfModule&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">&lt;/FilesMatch&gt;</span> </span></pre></div> </td></tr></table>
fontface, htaccess