Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Bash

Preventing Git cert error

env GIT_SSL_NO_VERIFY=true git clone https://bitbucket.org/user/repo.git
https://snipt.net/embed/517bc21864aa314d2a7bda5ef5f4f51f/
https://snipt.net/raw/517bc21864aa314d2a7bda5ef5f4f51f/
517bc21864aa314d2a7bda5ef5f4f51f
bash
Bash
2
2016-12-10T08:55:04
True
False
False
Nov 23, 2012 at 08:58 AM
/api/public/snipt/50666/
preventing-git-cert-error
<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>env <span class="nv">GIT_SSL_NO_VERIFY</span><span class="o">=</span><span class="nb">true</span> git clone https://bitbucket.org/user/repo.git </span></pre></div> </td></tr></table>
cert, git, https, prevent, ssh

PHP

Force Wordpress Admin Login Page to use SSL/HTTPS

1
2
3
4
5
6
7
8
<?php 
if(strstr($_SERVER["REQUEST_URI"],"/wp-login.php") && $_SERVER["HTTPS"] != "on") {
	$newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
	header("Location: $newurl");
	echo $newurl;
	exit();
}
?>
https://snipt.net/embed/1cd623503f4af3596ef9d5390b8f85fe/
https://snipt.net/raw/1cd623503f4af3596ef9d5390b8f85fe/
1cd623503f4af3596ef9d5390b8f85fe
php
PHP
8
2016-12-10T11:30:05
True
False
False
Aug 15, 2012 at 10:31 AM
/api/public/snipt/45737/
force-wordpress-admin-login-page-to-use-sslhttps
<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><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nb">strstr</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;REQUEST_URI&quot;</span><span class="p">],</span><span class="s2">&quot;/wp-login.php&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;HTTPS&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">&quot;on&quot;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$newurl</span> <span class="o">=</span> <span class="s2">&quot;https://&quot;</span> <span class="o">.</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_NAME&quot;</span><span class="p">]</span> <span class="o">.</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;REQUEST_URI&quot;</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a> <span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Location: </span><span class="si">$newurl</span><span class="s2">&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nv">$newurl</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">exit</span><span class="p">();</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
compliance, https, pci, redirect, ssl, wordpress

Text only

access insecure session for https with curl

curl -L -k https://10.1.2.240/DATA?
https://snipt.net/embed/a416d0b878d3f9731216324b658ddbde/
https://snipt.net/raw/a416d0b878d3f9731216324b658ddbde/
a416d0b878d3f9731216324b658ddbde
text
Text only
1
2016-12-08T02:10:46
True
False
False
/api/public/snipt/25293/
access-insecure-session-for-https-with-curl
<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>curl -L -k https://10.1.2.240/DATA? </span></pre></div> </td></tr></table>
curl, https, insecure

JavaScript

http2https bookmarklet

javascript:(function(){ if (location.href.indexOf("http") !== -1) { location.href = location.href.replace("http", "https"); } })();
https://snipt.net/embed/7c0cd0858956ac7022a1731c8d34dc87/
https://snipt.net/raw/7c0cd0858956ac7022a1731c8d34dc87/
7c0cd0858956ac7022a1731c8d34dc87
js
JavaScript
1
2016-12-09T23:28:19
True
False
False
/api/public/snipt/23249/
http2https-bookmarklet
<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="nx">javascript</span><span class="o">:</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> <span class="k">if</span> <span class="p">(</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s2">&quot;http&quot;</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span> <span class="nx">location</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s2">&quot;http&quot;</span><span class="p">,</span> <span class="s2">&quot;https&quot;</span><span class="p">);</span> <span class="p">}</span> <span class="p">})();</span> </span></pre></div> </td></tr></table>
bookmarklet, https, javascript

Text only

.htaccess to force https://www.* -- works with subdomains as well

1
2
3
4
5
6
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301]

RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
https://snipt.net/embed/ed8a60038cd1610054ee7538205034ac/
https://snipt.net/raw/ed8a60038cd1610054ee7538205034ac/
ed8a60038cd1610054ee7538205034ac
text
Text only
6
2016-12-10T13:29:00
True
False
False
/api/public/snipt/7209/
htaccess-to-force-httpswww-works-with-subdomains-as-well
<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>RewriteCond %{HTTP_HOST} ^domain.com$ </span><span id="L-3"><a name="L-3"></a>RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301] </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>RewriteCond %{HTTP_HOST} ^www.domain.com$ </span><span id="L-6"><a name="L-6"></a>RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L] </span></pre></div> </td></tr></table>
.htaccess, https, mod_rewrite, ssl

Bash

Création d'un certificat SSL autosigné

1
2
3
openssl genrsa -out server.key 1024
openssl req -new -x509 -days 365 -key server.key -out server.crt
openssl x509 -in server.crt -text -noout
https://snipt.net/embed/df70fc641c68772f9d6ec125e8c485d7/
https://snipt.net/raw/df70fc641c68772f9d6ec125e8c485d7/
df70fc641c68772f9d6ec125e8c485d7
bash
Bash
3
2016-12-10T05:37:29
True
False
False
/api/public/snipt/4296/
creation-dun-certificat-ssl-autosigne
<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>openssl genrsa -out server.key 1024 </span><span id="L-2"><a name="L-2"></a>openssl req -new -x509 -days <span class="m">365</span> -key server.key -out server.crt </span><span id="L-3"><a name="L-3"></a>openssl x509 -in server.crt -text -noout </span></pre></div> </td></tr></table>
cert, certificat, https, openssl, ssl

ApacheConf

Redirection HTTPS via le mod rewrite

1
2
3
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xxx.com/$1 [R,L]
https://snipt.net/embed/948f3b0f6b07780fa5ddf28e86c61379/
https://snipt.net/raw/948f3b0f6b07780fa5ddf28e86c61379/
948f3b0f6b07780fa5ddf28e86c61379
apacheconf
ApacheConf
4
2016-12-08T16:03:34
True
False
False
/api/public/snipt/4185/
redirection-https-via-le-mod-rewrite
<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> %{SERVER_PORT} <span class="m">80</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">RewriteRule</span> ^(.*)$ https://www.xxx.com/$1 [R,L] </span></pre></div> </td></tr></table>
admin, apache, apache2, https, modrewrite, redirection, serveur, ssl
Copyrighted, illegal, or inappropriate content? Email [email protected].