snipt

Ctrl+h for KB shortcuts

Bash

Wordpress: redirect old permalinks

1
2
3
4
# wordpress: handle redirect of old permalinks
RewriteEngine on 
RewriteCond %{QUERY_STRING} ^page_id=4$
RewriteRule .? http://yoursite.com/about-us/? [L,R=301]
https://snipt.net/embed/266b82c404f7df81549eb5b972066e1f/
/raw/266b82c404f7df81549eb5b972066e1f/
266b82c404f7df81549eb5b972066e1f
bash
Bash
4
2019-07-05T08:05:02
True
False
False
/api/public/snipt/24800/
wordpress-redirect-old-permalinks
<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="c1"># wordpress: handle redirect of old permalinks</span> </span><span id="L-2"><a name="L-2"></a>RewriteEngine on </span><span id="L-3"><a name="L-3"></a>RewriteCond %<span class="o">{</span>QUERY_STRING<span class="o">}</span> ^page_id<span class="o">=</span>4$ </span><span id="L-4"><a name="L-4"></a>RewriteRule .? http://yoursite.com/about-us/? <span class="o">[</span>L,R<span class="o">=</span>301<span class="o">]</span> </span></pre></div> </td></tr></table>
.htaccess, redirect, wordpress

Bash

.htaccess: Redirect to under construction page

1
2
3
4
5
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^99.41.147.210
RewriteCond %{REQUEST_URI} !/underconstruction\.html$
RewriteRule .* /underconstruction.html [R=302,L]
https://snipt.net/embed/bac9927e3cf2eb6d88b3bb7651c041a7/
/raw/bac9927e3cf2eb6d88b3bb7651c041a7/
bac9927e3cf2eb6d88b3bb7651c041a7
bash
Bash
5
2019-07-12T14:47:01
True
False
False
/api/public/snipt/20069/
htaccess-redirect-to-under-construction-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>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>REMOTE_HOST<span class="o">}</span> !^99.41.147.210 </span><span id="L-4"><a name="L-4"></a>RewriteCond %<span class="o">{</span>REQUEST_URI<span class="o">}</span> !/underconstruction<span class="se">\.</span>html$ </span><span id="L-5"><a name="L-5"></a>RewriteRule .* /underconstruction.html <span class="o">[</span><span class="nv">R</span><span class="o">=</span>302,L<span class="o">]</span> </span></pre></div> </td></tr></table>
.htaccess

Bash

.htaccess: Redirect of subfolders

# redirect all pages under directory "budget" to main index page
RedirectMatch "^/budget($|/(.*))$" http://www.site.com/
https://snipt.net/embed/b20a57d5dbb3d23cddff9c8ecb9467d9/
/raw/b20a57d5dbb3d23cddff9c8ecb9467d9/
b20a57d5dbb3d23cddff9c8ecb9467d9
bash
Bash
2
2019-07-14T23:21:09
True
False
False
/api/public/snipt/19589/
htaccess-redirect-of-subfolders
<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="c1"># redirect all pages under directory &quot;budget&quot; to main index page</span> </span><span id="L-2"><a name="L-2"></a>RedirectMatch <span class="s2">&quot;^/budget(</span>$<span class="s2">|/(.*))</span>$<span class="s2">&quot;</span> http://www.site.com/ </span></pre></div> </td></tr></table>
.htaccess

Bash

.htaccess: Allow only from IP

1
2
3
4
5
# Allow only from these 2 IPs

Order Deny,Allow
Deny from all
Allow from 311.311.311 322.322.322.322
https://snipt.net/embed/ac1c652330ecb71b572b2a63688c6988/
/raw/ac1c652330ecb71b572b2a63688c6988/
ac1c652330ecb71b572b2a63688c6988
bash
Bash
6
2019-07-13T16:58:31
True
False
False
/api/public/snipt/16358/
htaccess-allow-only-from-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> <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"># Allow only from these 2 IPs</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>Order Deny,Allow </span><span id="L-4"><a name="L-4"></a>Deny from all </span><span id="L-5"><a name="L-5"></a>Allow from 311.311.311 322.322.322.322 </span></pre></div> </td></tr></table>
.htaccess

Bash

Rewrite URL

1
2
3
4
# rbanh add for soft linking old dir
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^aaa/(.*)$ /bbb/$1 [L]
https://snipt.net/embed/d98e643cff9d543b682b23c0d772beae/
/raw/d98e643cff9d543b682b23c0d772beae/
d98e643cff9d543b682b23c0d772beae
bash
Bash
4
2019-07-09T19:32:33
True
False
False
/api/public/snipt/15994/
rewrite-url
<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="c1"># rbanh add for soft linking old dir</span> </span><span id="L-2"><a name="L-2"></a>RewriteEngine On </span><span id="L-3"><a name="L-3"></a>Options +FollowSymlinks </span><span id="L-4"><a name="L-4"></a>RewriteRule ^aaa/<span class="o">(</span>.*<span class="o">)</span>$ /bbb/<span class="nv">$1</span> <span class="o">[</span>L<span class="o">]</span> </span></pre></div> </td></tr></table>
.htaccess, url

Bash

.htaccess rewrite url

1
2
3
# check for form/thanks with or without trailing slash,
# and rewrite to /form?m=thanks
RewriteRule ^form/thanks(/$|$) /form?m=thanks
https://snipt.net/embed/4e5e6096a6f7e91d4bb7e528072de013/
/raw/4e5e6096a6f7e91d4bb7e528072de013/
4e5e6096a6f7e91d4bb7e528072de013
bash
Bash
3
2019-07-12T07:20:08
True
False
False
/api/public/snipt/13344/
htaccess-rewrite-url
<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="c1"># check for form/thanks with or without trailing slash,</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># and rewrite to /form?m=thanks</span> </span><span id="L-3"><a name="L-3"></a>RewriteRule ^form/thanks<span class="o">(</span>/$<span class="p">|</span>$<span class="o">)</span> /form?m<span class="o">=</span>thanks </span></pre></div> </td></tr></table>
.htaccess, apache, linux, rewrite

Bash

.htaccess file to lock down files with db or secure in the prefix

1
2
3
<FilesMatch "^(db|secure).*$">
deny from all
</FilesMatch>
https://snipt.net/embed/157dba3965602938b8e43226c77b9514/
/raw/157dba3965602938b8e43226c77b9514/
157dba3965602938b8e43226c77b9514
bash
Bash
4
2019-06-10T12:15:35
True
False
False
/api/public/snipt/12528/
htaccess-file-to-lock-down-files-with-db-or-secure-in-the-prefix
<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>&lt;FilesMatch <span class="s2">&quot;^(db|secure).*</span>$<span class="s2">&quot;</span>&gt; </span><span id="L-2"><a name="L-2"></a>deny from all </span><span id="L-3"><a name="L-3"></a>&lt;/FilesMatch&gt; </span></pre></div> </td></tr></table>
.htaccess, apache, linux

Bash

Rewrite .cfm files to files with .cfm

1
2
3
4
5
6
RewriteEngine On
Options -Indexes

# redirect all .cfm files to files without .cfm
RedirectMatch 301 ^(.*)\index.cfm$ $1
RedirectMatch 301 ^(.*)\.cfm$ $1
https://snipt.net/embed/ae4580230f1cfe7a14b823ef5e0fb2e0/
/raw/ae4580230f1cfe7a14b823ef5e0fb2e0/
ae4580230f1cfe7a14b823ef5e0fb2e0
bash
Bash
6
2019-07-12T14:33:36
True
False
False
/api/public/snipt/12142/
rewrite-cfm-files-to-files-with-cfm
<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>Options -Indexes </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># redirect all .cfm files to files without .cfm</span> </span><span id="L-5"><a name="L-5"></a>RedirectMatch <span class="m">301</span> ^<span class="o">(</span>.*<span class="o">)</span><span class="se">\i</span>ndex.cfm$ <span class="nv">$1</span> </span><span id="L-6"><a name="L-6"></a>RedirectMatch <span class="m">301</span> ^<span class="o">(</span>.*<span class="o">)</span><span class="se">\.</span>cfm$ <span class="nv">$1</span> </span></pre></div> </td></tr></table>
.htaccess, apache, linux, rewrite