Skip to content

Instantly share code, notes, and snippets.

View BAHC's full-sized avatar

BAHC

View GitHub Profile
@BAHC
BAHC / .htaccess
Last active May 31, 2019 01:55
Redirect using mod_rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([A-Za-z]+)/([A-Za-z\+]+)/([0-9]+)/?$ tour/?id=$3&city=$2&country=$1 [NC]
RewriteRule ^([A-Za-z]+)/([A-Za-z\+]+)/?$ city/?city=$2&country=$1 [NC]
RewriteRule ^([A-Za-z^index]+)/?$ country/?country=$1 [NC]
@BAHC
BAHC / functions.php
Created May 31, 2019 02:15
Custom routes in WP theme
<?php
//file /wp-content/themes/current-theme/functions.php
function custom_addRoutes() {
add_rewrite_rule('^([A-Za-z]+)/([A-Za-z\+]+)/([0-9]+)/?$', 'tour/?id=$matches[3]&city=$matches[2]&country=$matches[1]', 'top');
add_rewrite_rule('^([A-Za-z]+)/([A-Za-z\+]+)/?$', 'city/?city_name_en=$matches[2]&country=$matches[1]', 'top');
add_rewrite_rule('^([A-Za-z^index]+)/?$', 'country/?country_name_en=$matches[1]', 'top');
}
add_action('init', 'custom_addRoutes');
@BAHC
BAHC / mysqli.php
Created May 31, 2019 02:26
MySQL Improved
<?php
$db_user = 'root';
$db_pass = 'toor';
$db_host = 'localhost';
$db_port = 3306;
$db_name = 'my_db';
$db_encoding = 'utf8';
//mysqli_connect(host, username, password, dbname, port, socket);