snipt

Ctrl+h for KB shortcuts

PHP

Change WordPress URL search base

1
2
3
4
5
6
<?php
function vital_custom_search_base() {
    $GLOBALS['wp_rewrite']->search_base = 'search-results';
}

add_action( 'init', 'vital_custom_search_base' );
https://snipt.net/embed/014873dfcc188991ccee13318ce8a89d/
https://snipt.net/raw/014873dfcc188991ccee13318ce8a89d/
014873dfcc188991ccee13318ce8a89d
php
PHP
6
2016-09-28T15:03:39
True
False
False
Jul 05, 2016 at 03:15 PM
/api/public/snipt/147339/
change-wordpress-url-search-base
<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 id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">vital_custom_search_base</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$GLOBALS</span><span class="p">[</span><span class="s1">&#39;wp_rewrite&#39;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">search_base</span> <span class="o">=</span> <span class="s1">&#39;search-results&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;init&#39;</span><span class="p">,</span> <span class="s1">&#39;vital_custom_search_base&#39;</span> <span class="p">);</span> </span></pre></div> </td></tr></table>
permalinks, rewrite, wordpress

Text only

Rewrite Xmap URL

1
2
3
4
5
6
RewriteCond %{REQUEST_URI} ^/es/sitemap.xml
RewriteRule .* /es/index.php?option=com_xmap&view=xml&tmpl=component&id=1
RewriteCond %{REQUEST_URI} ^/en/sitemap.xml
RewriteRule .* /en/index.php?option=com_xmap&view=xml&tmpl=component&id=2
RewriteCond %{REQUEST_URI} ^/pt/sitemap.xml
RewriteRule .* /pt/index.php?option=com_xmap&view=xml&tmpl=component&id=3
https://snipt.net/embed/29b62e0c11755e05065242cf9fcd3991/
https://snipt.net/raw/29b62e0c11755e05065242cf9fcd3991/
29b62e0c11755e05065242cf9fcd3991
text
Text only
6
2016-09-26T10:28:37
True
False
False
Apr 01, 2014 at 11:48 AM
/api/public/snipt/126512/
rewrite-xmap-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> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>RewriteCond %{REQUEST_URI} ^/es/sitemap.xml </span><span id="L-2"><a name="L-2"></a>RewriteRule .* /es/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=1 </span><span id="L-3"><a name="L-3"></a>RewriteCond %{REQUEST_URI} ^/en/sitemap.xml </span><span id="L-4"><a name="L-4"></a>RewriteRule .* /en/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=2 </span><span id="L-5"><a name="L-5"></a>RewriteCond %{REQUEST_URI} ^/pt/sitemap.xml </span><span id="L-6"><a name="L-6"></a>RewriteRule .* /pt/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=3 </span></pre></div> </td></tr></table>
htaccess, joomla, rewrite, sitemap, xmap

Nginx configuration file

Backbone.js rewrite for Nginx

1
2
3
4
5
        location / {
        		if (!-e $request_filename){
        			rewrite ^(.*)$ /index.html break;
        		}
        }
https://snipt.net/embed/ab9ed4a5f3702f4c11307dd1f510415f/
https://snipt.net/raw/ab9ed4a5f3702f4c11307dd1f510415f/
ab9ed4a5f3702f4c11307dd1f510415f
nginx
Nginx configuration file
5
2016-09-27T14:50:21
True
False
False
Apr 30, 2013 at 08:22 PM
/api/public/snipt/60379/
backbonejs-rewrite-for-nginx
<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 id="L-1"><a name="L-1"></a> <span class="k">location</span> <span class="s">/</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kn">if</span> <span class="s">(!-e</span> <span class="nv">$request_filename</span><span class="s">)</span><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="kn">rewrite</span> <span class="s">^(.*)</span>$ <span class="s">/index.html</span> <span class="s">break</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">}</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span></pre></div> </td></tr></table>
backbone.js, nginx, rewrite, rewrites

ApacheConf

Ignorando uma pasta no .htaccess

RewriteRule ^nome_pasta/.*$ - [PT]
https://snipt.net/embed/c9dbdb9a708bc98daf7a391d2435f37a/
https://snipt.net/raw/c9dbdb9a708bc98daf7a391d2435f37a/
c9dbdb9a708bc98daf7a391d2435f37a
apacheconf
ApacheConf
1
2016-09-26T06:16:49
True
False
False
/api/public/snipt/44092/
ignorando-uma-pasta-no-htaccess
<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 id="L-1"><a name="L-1"></a><span class="nb">RewriteRule</span> ^nome_pasta/.*$ - [PT] </span></pre></div> </td></tr></table>
apache, cakephp, mvc, rewrite

JavaScript

deny 360SE

1
2
3
4
if ($http_user_agent ~ (360SE) )   
{   
    return 404;   
}
https://snipt.net/embed/96c853a41a4756a2c1d836982b181c2c/
https://snipt.net/raw/96c853a41a4756a2c1d836982b181c2c/
96c853a41a4756a2c1d836982b181c2c
js
JavaScript
4
2016-09-26T14:06:46
True
False
False
/api/public/snipt/26896/
deny-360se
<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 id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="p">(</span><span class="nx">$http_user_agent</span> <span class="o">~</span> <span class="p">(</span><span class="mi">360</span><span class="nx">SE</span><span class="p">)</span> <span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="mi">404</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
rewrite

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/
https://snipt.net/raw/4e5e6096a6f7e91d4bb7e528072de013/
4e5e6096a6f7e91d4bb7e528072de013
bash
Bash
3
2016-09-28T05:33:11
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 id="L-1"><a name="L-1"></a><span class="c"># check for form/thanks with or without trailing slash,</span> </span><span id="L-2"><a name="L-2"></a><span class="c"># 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="nv">$|$)</span> /form?m<span class="o">=</span>thanks </span></pre></div> </td></tr></table>
.htaccess, apache, linux, rewrite

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/
https://snipt.net/raw/ae4580230f1cfe7a14b823ef5e0fb2e0/
ae4580230f1cfe7a14b823ef5e0fb2e0
bash
Bash
6
2016-09-28T08:13:15
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 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="c"># 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
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.