Nginx Rewrite Rule to Add Slash to The End of Any URL

Solution 1 If you want to append a slash “/” to the end of any URL, such as: website.com/category => website.com/category/website.com/category => website.com/category/ You can use this Nginx rewrite rule: rewrite ^(.*[^/])$ $1/ permanent;rewrite ^(.*[^/])$ $1/ permanent; Solution 2 If you want to append the slash only if the URL NOT contains a dot, example: […]

How to Enable HTTP/2 on Nginx

It is simple to enable HTTP/2 on Nginx, just replace this: listen 443 ssl;listen 443 ssl; With this: listen 443 ssl http2;listen 443 ssl http2; And reload your Nginx configuration: service nginx reloadservice nginx reload You can find here a complete SSL configuration: Let’s Encrypt on Nginx and SSL Grade A+

Example usage PHP Namespace and Use

Pay attention to the order, namespace goes at first line: namespace LayerShifter\TLDExtract\Tests;   include_once __DIR__ . ‘/vendor/autoload.php’;   use LayerShifter\TLDDatabase\Store; use LayerShifter\TLDExtract\Exceptions\RuntimeException; use LayerShifter\TLDExtract\Extract; use LayerShifter\TLDExtract\Result;   // Below here insert custom functions etc   $extract = new Extract();   $extract->setExtractionMode(Extract::MODE_ALLOW_ICCAN);   $result = $extract->parse(‘a.b.blogspot.com’);   print_r($result->getRegistrableDomain());namespace LayerShifter\TLDExtract\Tests; include_once __DIR__ . ‘/vendor/autoload.php’; use LayerShifter\TLDDatabase\Store; use […]

Composer No version set (parsed as 1.0.0) is satisfiable

If you get these error messages via composer: Your requirements could not be resolved to an installable set of packages. … – The requested package library_name No version set (parsed as 1.0.0) is satisfiable by library_name[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability. … Installation failed, reverting ./composer.json to […]

Install Composer with Curl

Open the folder where is composer.json and then type: curl -sS https://getcomposer.org/installer | phpcurl -sS https://getcomposer.org/installer | php This will create the file composer.phar. To run a composer command type: php composer.phar [command]php composer.phar [command] Example: php composer.phar require php-curl-class/php-curl-classphp composer.phar require php-curl-class/php-curl-class

PHP Validate URL

PHP function that validates and URL: function is_website_url($url, $allowed_schemes = array(‘http’, ‘https’)) { $validate_url = !(filter_var($url, FILTER_VALIDATE_URL) === false); $scheme = parse_url($url, PHP_URL_SCHEME); return $validate_url && in_array($scheme, $allowed_schemes, true); }function is_website_url($url, $allowed_schemes = array(‘http’, ‘https’)) { $validate_url = !(filter_var($url, FILTER_VALIDATE_URL) === false); $scheme = parse_url($url, PHP_URL_SCHEME); return $validate_url && in_array($scheme, $allowed_schemes, true); } Usage: $url […]

PHP Curl Class

Awesome PHP curl class found on github: $ composer require php-curl-class/php-curl-class &> /dev/null $ php –interactive php > require __DIR__ . ‘/vendor/autoload.php’; php > use \Curl\Curl; php > $curl = new \Curl\Curl(); php > $curl->setBasicAuthentication(‘user’, ‘pass’); php > $curl->get(‘https://api.github.com/user’); php > echo $curl->httpStatusCode; 200 php > echo $curl->responseHeaders[‘content-type’]; application/json; charset=utf-8 php > echo $curl->response->login; php-curl-class […]

Example FFprobe commands

Extract index, codec name and codec type: ffprobe -v error -show_entries stream=index,codec_name,codec_type input.mkvffprobe -v error -show_entries stream=index,codec_name,codec_type input.mkv Example output: [STREAM] index=0 codec_name=h264 codec_type=video [/STREAM] [STREAM] index=1 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=2 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=3 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] index=4 codec_name=ass codec_type=subtitle [/STREAM][STREAM] index=0 codec_name=h264 codec_type=video [/STREAM] [STREAM] index=1 codec_name=vorbis codec_type=audio [/STREAM] [STREAM] […]

Check if a website is located in China

To check if a website is located in China you can parse the NS DNS records: host => rbacc-us.com class => IN ttl => 86400 type => NS target => f1g1ns1.dnspod.net   host => rbacc-us.com class => IN ttl => 86400 type => NS target => f1g1ns2.dnspod.nethost => rbacc-us.com class => IN ttl => 86400 […]

Disable WordPress Embeds

Some users have reported that the json URLs are sometimes indexed by Google: http://www.site.com/wp-json/oembed/1.0/embed?url=http%3A…http://www.site.com/wp-json/oembed/1.0/embed?url=http%3A… To disable WordPress embeds you can use this plugin: https://wordpress.org/plugins/disable-embeds/ You can also remove these references in HTML head: <link rel=’https://api.w.org/’ href=’http://example.com/wp-json/’ /> <link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=…" /> <link rel="alternate" type="text/xml+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=…" /><link rel=’https://api.w.org/’ href=’http://example.com/wp-json/’ /> <link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=…" /> […]