snipt

Ctrl+h for KB shortcuts

ApacheConf

HTACCESS - Redirect all other users to a Coming Soon page

1
2
3
4
5
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^12\.345\.67\.89
RewriteCond %{REQUEST_URI} !/coming-soon\.html$
RewriteRule (.*)$ /coming-soon.html [R=302,L]
https://snipt.net/embed/df37eb834320aeb4384ff90e7dc1958c/
/raw/df37eb834320aeb4384ff90e7dc1958c/
df37eb834320aeb4384ff90e7dc1958c
apacheconf
ApacheConf
5
2019-07-15T05:37:31
True
False
False
/api/public/snipt/30745/
htaccess-redirect-all-other-users-to-a-coming-soon-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="nb">Options</span> +FollowSymlinks </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> %{REMOTE_HOST} !^12\.345\.67\.89 </span><span id="L-4"><a name="L-4"></a><span class="nb">RewriteCond</span> %{REQUEST_URI} !/coming-soon\.html$ </span><span id="L-5"><a name="L-5"></a><span class="nb">RewriteRule</span> (.*)$ <span class="sx">/coming-soon.html</span> [R=302,L] </span></pre></div> </td></tr></table>
htaccess

ApacheConf

HTACCESS - Redirect all but certain directory

1
2
3
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/somefolder/ 
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
https://snipt.net/embed/b7daea9d319ae56c5c9dfd5684839431/
/raw/b7daea9d319ae56c5c9dfd5684839431/
b7daea9d319ae56c5c9dfd5684839431
apacheconf
ApacheConf
3
2019-07-12T22:38:21
True
False
False
/api/public/snipt/30435/
htaccess-redirect-all-but-certain-directory
<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> %{REQUEST_URI} !^/somefolder/ </span><span id="L-3"><a name="L-3"></a><span class="nb">RewriteRule</span> (.*) http://www.domain.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
htaccess

Text only

htaccess expires settings

1
2
3
4
5
6
7
8
# In the web root .htaccess file
# Modify the expires time as you see fit

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 30 days"
ExpiresByType image/x-icon "access plus 60 days"
</IfModule>
https://snipt.net/embed/8774b1dcf1b48554fd54fc84afa5f186/
/raw/8774b1dcf1b48554fd54fc84afa5f186/
8774b1dcf1b48554fd54fc84afa5f186
text
Text only
8
2019-07-09T09:26:48
True
False
False
/api/public/snipt/29103/
htaccess-expires-settings
<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> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a># In the web root .htaccess file </span><span id="L-2"><a name="L-2"></a># Modify the expires time as you see fit </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>&lt;IfModule mod_expires.c&gt; </span><span id="L-5"><a name="L-5"></a>ExpiresActive On </span><span id="L-6"><a name="L-6"></a>ExpiresDefault &quot;access plus 30 days&quot; </span><span id="L-7"><a name="L-7"></a>ExpiresByType image/x-icon &quot;access plus 60 days&quot; </span><span id="L-8"><a name="L-8"></a>&lt;/IfModule&gt; </span></pre></div> </td></tr></table>
expires, htaccess

ApacheConf

HTACCESS - Maintenance Mode

1
2
3
4
5
# redirect all visitors to alternate site but retain full access for you
ErrorDocument 403 http://www.alternate-site.com
Order deny,allow
Deny from all
Allow from 99.88.77.66
https://snipt.net/embed/24ae82e5ebb1a44e1855623b3c55eb49/
/raw/24ae82e5ebb1a44e1855623b3c55eb49/
24ae82e5ebb1a44e1855623b3c55eb49
apacheconf
ApacheConf
5
2019-06-29T13:18:01
True
False
False
Dec 14, 2016 at 05:32 PM
/api/public/snipt/29098/
htaccess-maintenance-mode
<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"># redirect all visitors to alternate site but retain full access for you</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">ErrorDocument</span> <span class="m">403</span> http://www.alternate-site.com </span><span id="L-3"><a name="L-3"></a><span class="nb">Order</span> deny,allow </span><span id="L-4"><a name="L-4"></a><span class="nb">Deny</span> from <span class="k">all</span> </span><span id="L-5"><a name="L-5"></a><span class="nb">Allow</span> from <span class="m">99.88.77.66</span> </span></pre></div> </td></tr></table>
htaccess

ApacheConf

HTACCESS - Prevent Hotlinking

1
2
3
4
5
6
7
# stop hotlinking and serve alternate content
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.com/.*$ [NC]
 RewriteRule .*\.(gif|jpg)$ http://www.domain.com/eatme.jpg [R,NC,L]
</ifModule>
https://snipt.net/embed/727c6e296108a3ec71566d72dfaa5540/
/raw/727c6e296108a3ec71566d72dfaa5540/
727c6e296108a3ec71566d72dfaa5540
apacheconf
ApacheConf
7
2019-07-02T02:15:59
True
False
False
Feb 14, 2014 at 11:54 AM
/api/public/snipt/29097/
htaccess-prevent-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><span class="c"># stop hotlinking and serve alternate content</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">&lt;IfModule</span> <span class="s">mod_rewrite.c</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">RewriteEngine</span> <span class="k">on</span> </span><span id="L-4"><a name="L-4"></a> <span class="nb">RewriteCond</span> %{HTTP_REFERER} !^$ </span><span id="L-5"><a name="L-5"></a> <span class="nb">RewriteCond</span> %{HTTP_REFERER} !^http://(www\.)?domain\.com/.*$ [NC] </span><span id="L-6"><a name="L-6"></a> <span class="nb">RewriteRule</span> .*\.(gif|jpg)$ http://www.domain.com/eatme.jpg [R,NC,L] </span><span id="L-7"><a name="L-7"></a><span class="nt">&lt;/ifModule&gt;</span> </span></pre></div> </td></tr></table>
htaccess

ApacheConf

HTACCESS - Redirect all of a certain file type

RedirectMatch 301 (.*)\.asp$ http://www.domain.com/newpage.html
https://snipt.net/embed/1ef58e0b52222464a56a5703c2649f7a/
/raw/1ef58e0b52222464a56a5703c2649f7a/
1ef58e0b52222464a56a5703c2649f7a
apacheconf
ApacheConf
1
2019-07-10T17:32:24
True
False
False
/api/public/snipt/29005/
htaccess-redirect-all-of-a-certain-file-type
<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">RedirectMatch</span> <span class="m">301</span> (.*)\.asp$ http://www.domain.com/newpage.html </span></pre></div> </td></tr></table>
htaccess

ApacheConf

HTACCESS - Redirect IP to Domain

1
2
3
4
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^123\.456\.789\.091
RewriteRule (.*)$ http://www.primarydomain.com/$1 [R=301,L]
https://snipt.net/embed/ed41722bfb188328d654ece9f2e7fa8a/
/raw/ed41722bfb188328d654ece9f2e7fa8a/
ed41722bfb188328d654ece9f2e7fa8a
apacheconf
ApacheConf
4
2019-07-12T00:12:48
True
False
False
/api/public/snipt/29004/
htaccess-redirect-ip-to-domain
<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="nb">Options</span> +FollowSymLinks </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} ^123\.456\.789\.091 </span><span id="L-4"><a name="L-4"></a><span class="nb">RewriteRule</span> (.*)$ http://www.primarydomain.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
htaccess

ApacheConf

HTACCESS - Redirect Folder With Space in the Name

RewriteRule ^some(\ |\%20)directory/ http://www.domain.com/new-directory/ [R=301,L]
https://snipt.net/embed/dbb035058be7984d28d085b43718bfe9/
/raw/dbb035058be7984d28d085b43718bfe9/
dbb035058be7984d28d085b43718bfe9
apacheconf
ApacheConf
1
2019-06-27T16:54:28
True
False
False
/api/public/snipt/29000/
htaccess-redirect-folder-with-space-in-the-name
<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> ^some(\ |\%20)directory/ http://www.domain.com/new-directory/ [R=301,L] </span></pre></div> </td></tr></table>
htaccess