snipt

Ctrl+h for KB shortcuts

PHP

Validate domain name

1
2
3
4
5
6
$url = "https://snipt.net/";
if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) {
    echo "Your url is ok.";
} else {
    echo "Wrong url.";
}
https://snipt.net/embed/f5ed73e75cd63fe737818de7c6559938/
/raw/f5ed73e75cd63fe737818de7c6559938/
f5ed73e75cd63fe737818de7c6559938
php
PHP
6
2019-08-23T17:07:23
True
False
False
/api/public/snipt/44645/
validate-domain-name
<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="x">$url = &quot;https://snipt.net/&quot;;</span> </span><span id="L-2"><a name="L-2"></a><span class="x">if (preg_match(&#39;/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i&#39;, $url)) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> echo &quot;Your url is ok.&quot;;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">} else {</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> echo &quot;Wrong url.&quot;;</span> </span><span id="L-6"><a name="L-6"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
domain, validate

PHP

PHP Absolute Server Address

<?php $domain = 'http://www.'.$_SERVER["SERVER_NAME"]; ?>
https://snipt.net/embed/3399f6bb63ba3a8d1b29bb653d36268d/
/raw/3399f6bb63ba3a8d1b29bb653d36268d/
3399f6bb63ba3a8d1b29bb653d36268d
php
PHP
1
2019-08-22T15:56:04
True
False
False
/api/public/snipt/6101/
php-absolute-server-address
<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="cp">&lt;?php</span> <span class="nv">$domain</span> <span class="o">=</span> <span class="s1">&#39;http://www.&#39;</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="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
absolute, domain, php, server

ApacheConf

domain redirect per .htaccess

1
2
3
4
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.domain\.tld$
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
https://snipt.net/embed/89d2230c52a30bd0905be0cfe7df42f0/
/raw/89d2230c52a30bd0905be0cfe7df42f0/
89d2230c52a30bd0905be0cfe7df42f0
apacheconf
ApacheConf
4
2019-08-23T17:07:45
True
False
False
/api/public/snipt/1627/
domain-redirect-per-htaccess
<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">RewriteEngine</span> <span class="k">on</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nb">RewriteCond</span> %{HTTP_HOST} !^www\.domain\.tld$ </span><span id="L-4"><a name="L-4"></a><span class="nb">RewriteRule</span> ^(.*)$ http://www.domain.tld/$1 [L,R=301] </span></pre></div> </td></tr></table>
domain, redirect