.htaccess
HTTP → HTTPS + WWW → non-WWW
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Alternative:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
.htaccess
HTTP → HTTPS + non-WWW → WWW
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
.htaccess
non-WWW → WWW redirect
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# or
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
# or (with IfModule)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
.htaccess
HTTP → HTTPS only
Goes in: .htaccess file
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
.htaccess
HTTPS → HTTP (force non-SSL)
Goes in: .htaccess file
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
.htaccess
IP Address → Domain Redirect
Goes in: .htaccess file
RewriteCond %{HTTP_HOST} ^162\.144\.52\.225
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
.htaccess
WWW → non-WWW redirect
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
# or
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [nocase]
RewriteRule ^(.*) http://example.com/$1 [last,redirect=301]
.htaccess
Homepage HTTPS but inner pages excluded
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
web.config
non-WWW → WWW (multiple variants)
Goes in: web.config file
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config
IP Address → Domain Redirect
Goes in: web.config file
<rule name="IP Hit" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="118.139.173.133" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:1}" redirectType="Permanent" />
</rule>
web.config
404 → 301 specific page redirect
Goes in: web.config file
<location path="about-us.html">
<system.webServer>
<httpRedirect enabled="true"
destination="http://www.domain.com/About-Hotels"
httpResponseStatus="Permanent" />
</system.webServer>
</location>
.htaccess
Fix Mixed Content (upgrade HTTP → HTTPS)
Goes in: .htaccess file
Header set Content-Security-Policy: upgrade-insecure-requests env=HTTPS
WordPress
Create WordPress Admin User via PHP
Goes in: wp-content/themes/[theme]/functions.php
function wpb_admin_account() {
$user = 'username';
$pass = 'password';
$email = '[email protected]';
if ( !username_exists($user) && !email_exists($email) ) {
$user_id = wp_create_user($user, $pass, $email);
$user = new WP_User($user_id);
$user->set_role('administrator');
}
}
add_action('init', 'wpb_admin_account');
Other
WhatsApp Widget — two options
Goes in: Before closing </body> tag
<!-- Option 1: WhatsHelp.io widget -->
<script type="text/javascript">
(function () {
var options = {
whatsapp: "+97111111111",
call_to_action: "Message us",
position: "right",
};
var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host;
var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true;
s.src = url + '/widget-send-button/js/init.js';
s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
})();
</script>
<!-- Option 2: Simple anchor widget -->
<a class="whats-app" href="https://api.whatsapp.com/send?phone=971522330099&text=Hello" target="_blank">
<img src="whatsapp.png">
</a>
/* CSS for Option 2 */
.whats-app {
position: fixed; width: 50px; height: 50px; bottom: 22px;
background-color: #25d366; color: #FFF; border-radius: 50px;
text-align: center; font-size: 30px; box-shadow: 3px 4px 3px #999;
right: 85px; z-index: 100;
}
Other
Read More / Read Less — 3 options
Goes in: JS file + HTML where required
<!-- Option 1: Native HTML <details> -->
<details>
<summary>Show/Hide</summary>
Content goes here
</details>
/* CSS to change summary text */
details summary::after { content: '▸ Read More'; }
details[open] summary::after { content: '▾ Hide'; }
// Option 2: JS toggle
function showtext(id) {
var x = document.getElementById(id);
x.style.display = (x.style.display === "none") ? "block" : "none";
}
// HTML: <a onclick="showtext('off')" href="javascript:void(0);">...</a>
// <div id="off" style="display:none;">Content</div>
// Option 3: Read more with dots
function myFunction() {
var dots = document.getElementById("dots");
var more = document.getElementById("more");
var btn = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline"; btn.innerHTML = "Read more"; more.style.display = "none";
} else {
dots.style.display = "none"; btn.innerHTML = "Read less"; more.style.display = "inline";
}
}
Other
SquareSpace: Hide banner title & description
Goes in: Page → Advanced Code Box
<style> .page-title { opacity: 0 } </style>
<style> .page-desc { opacity: 0 } </style>
Shopify
Remove shop name from title tag
Goes in: theme.liquid — replace existing <title> tag
<title>
{{ page_title }}
{%- if current_tags -%}
{%- assign meta_tags = current_tags | join: ', ' -%}
– {{ 'general.meta.tags' | t: tags: meta_tags }}
{%- endif -%}
{%- if current_page != 1 -%}
– {{ 'general.meta.page' | t: page: current_page }}
{%- endif -%}
</title>
WordPress
Show different content per page (PHP)
Goes in: PHP template file where required
<?php if ($_SERVER['REQUEST_URI'] == '/page1') { ?>
<title>Title 1</title>
<?php } elseif ($_SERVER['REQUEST_URI'] == '/page2') { ?>
<title>Title 2</title>
<?php } else { ?>
<title>Default Title</title>
<?php } ?>
WordPress
Hide page title by Page ID
Goes in: functions.php
add_filter('the_title', 'remove_page_title', 10, 2);
function remove_page_title($title, $id) {
$hide_ids = array(7, 17, 53); // add Page IDs here
foreach ($hide_ids as $page_id) {
if ($page_id == $id) return '';
}
return $title;
}
WordPress
Add code on specific page by ID
Goes in: Template PHP file where required
<?php
$page_id_custom = 1; // change page id here
if (is_page($page_id_custom)) {
?>
<div class="tracking-code">Insert-Code-Here</div>
<?php } ?>
WordPress
Redirect 404 to another page (301)
Goes in: functions.php
add_action('template_redirect', 'notfoundtopage');
function notfoundtopage() {
if (is_404()) {
wp_redirect('https://abc.com/contact-us/', 301);
}
}
WordPress
301 redirect HTTPS non-WWW → HTTPS WWW
Goes in: Header PHP file
<?php
if (strpos($_SERVER['HTTP_HOST'], 'www') === false) {
$protocol = isset($_SERVER['HTTPS']) && filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)
? 'https' : 'http';
header("Location: $protocol://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true, 301);
}
?>
JavaScript
Replace H1 tags with H2 using JS
Goes in: footer.php as inline script
// Replace all h1.vc_custom_heading with h2
var els = document.querySelectorAll('h1.vc_custom_heading');
for (var i = 0; i < els.length; i++) {
els[i].outerHTML = '<h2>' + els[i].innerHTML + '</h2>';
}
// Replace all h1s except the 3rd one
var els2 = document.querySelectorAll('h1');
for (var i = 0; i < els2.length; i++) {
if (i !== 2) {
els2[i].outerHTML = '<h2>' + els2[i].innerHTML + '</h2>';
}
}
JavaScript
Replace heading tags — exclude specific URLs
Goes in: footer.php as inline script
var currenturl = window.location.href;
if (currenturl === "https://example.com/page1/") {
// skip
} else if (currenturl === "https://example.com/page2/") {
// skip
} else {
var els = document.querySelectorAll('.wpb_wrapper h2');
els[0].outerHTML = '<h1>' + els[0].innerHTML + '</h1>';
}
WordPress
Show category description on product category page
Goes in: taxonomy-product_cat.php
<?php
if (strlen(category_description()) > 0) {
echo '<div id="catdesc">';
echo category_description();
echo '</div>';
}
?>
JavaScript
Auto-set alt tags for all images from filename
Goes in: footer.php
var images = document.getElementsByTagName('img');
for (var i = 0, l = images.length; i < l; i++) {
var fullPath = images[i].src;
var filename = fullPath.replace(/^.*[\\\/]/, '');
images[i].setAttribute("alt", filename);
}
WordPress
Disable Gutenberg — restore Classic Editor
Goes in: functions.php
// Method 1
add_filter("use_block_editor_for_post_type", "disable_gutenberg_editor");
function disable_gutenberg_editor() { return false; }
// Method 2 (cleaner)
add_filter('use_block_editor_for_post', '__return_false');
add_filter('use_block_editor_for_post_type', '__return_false');
.htaccess
Set custom 404 error page
Goes in: .htaccess file
# Change URL to your 404 page
ErrorDocument 404 https://www.abc.com/404.html
WordPress
Embed Contact Form 7 in PHP
Goes in: PHP template file where required
<?php
// Change form ID below
echo do_shortcode('[contact-form-7 id="251" title="Contact form 1"]');
?>
Other
Joomla: Remove duplicate title from content body
Goes in: /components/com_content/views/article/tmpl/default.php — remove this:
<!-- Remove the following block from the file -->
<div class="componentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
<?php echo $this->escape($this->params->get('page_title')); ?>
</div>
robots.txt
Block major crawlers (SEMrush, Ahrefs, etc.)
Goes in: robots.txt file
User-agent: SemrushBot
Disallow: /
User-agent: AhrefsBot
Disallow: /
User-agent: MJ12bot
Disallow: /
User-agent: rogerbot
Disallow: /
User-agent: Baiduspider
Disallow: /
User-agent: ia_archiver
Disallow: /
User-agent: xenu
Disallow: /
User-agent: gigabot
Disallow: /
WordPress
Fix “Allowed memory size exhausted” error
Goes in: wp-config.php
define('WP_MEMORY_LIMIT', '64M');
Other
OpenCart: Redirect index.php?route=common/home → homepage
Goes in: .htaccess file
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^index\.php$ http://%{HTTP_HOST}? [R=301,L]
.htaccess
Remove trailing slash
Goes in: .htaccess file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\/$ /$1 [L,R=301]
.htaccess
Add trailing slash
Goes in: .htaccess file
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
web.config
Add trailing slash
Goes in: web.config file
<rule name="Add trailing slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.html$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.aspx$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
web.config
Remove trailing slash
Goes in: web.config file
<rewrite>
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$ " />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
WordPress
Redirect by hashtag (#!) in WordPress
Goes in: functions.php
function themee_hash_redirects() { ?>
<script type="text/javascript">
function themee_hashtag_redirect(hashtag, url) {
var locationHash = document.location.hash;
if (locationHash.match(/#!/img)) {
if (hashtag == locationHash) { document.location.href = url; }
}
}
themee_hashtag_redirect('#!contact', '/contact/');
themee_hashtag_redirect('#!about', '/about/');
</script>
<?php }
add_action('wp_footer', 'themee_hash_redirects');
.htaccess
Redirect whole site but exclude one folder
Goes in: .htaccess file
# Redirect everything except /ar/ folder
RedirectMatch 301 ^/((?!ar).*)$ https://www.abc.com/$1
.htaccess
Remove .html extension from URLs
Goes in: .htaccess file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
web.config
Redirect uppercase URLs to lowercase
Goes in: web.config file
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" pattern="\.aspx$" />
<add input="{REQUEST_FILENAME}" pattern="\." negate="true" />
</conditions>
</rule>
.htaccess
Redirect specific directory
Goes in: .htaccess file
# Redirect directory only (no inner pages)
RedirectMatch 301 ^/uae/*$ http://www.abc.com/
# Redirect directory + all inner pages
RedirectMatch 301 ^/uae/.*$ http://www.abc.com/
robots.txt
WordPress robots.txt template
Goes in: robots.txt file
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-content/uploads/media-from-ftp-tmp/
Sitemap: https://www.abc.com/sitemap_index.xml
robots.txt
Simple robots.txt
Goes in: robots.txt file
User-agent: *
Disallow:
Sitemap: https://abc.com/sitemap.xml
.htaccess
Remove .php extension from URLs
Goes in: .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.+)\.php$
RewriteRule (.*)\.php$ /$1/ [R=301,L]
CSS
Stop iOS from styling input fields and buttons
Goes in: CSS file
input[type="submit"],
input[type="text"],
button {
-webkit-appearance: none !important;
-moz-appearance: none !important;
appearance: none !important;
}
.htaccess
Remove a directory from URL (301 redirect)
Goes in: .htaccess file
RewriteCond %{REQUEST_URI} ^/directory/ [NC]
RewriteRule /(.*) https://www.abc.com/$1 [R=301,L]
JavaScript
Remove attributes from elements
Goes in: JS file
// Remove 'style' attribute from first element with class + tag
var list = document.getElementsByClassName("classname")[0];
list.getElementsByTagName("tagname")[0].removeAttribute("style");
WordPress
Show custom field value (ACF)
Goes in: Template PHP file
<?php the_field('your-field-name'); ?>
WordPress
Update Yoast SEO scores via SQL
Goes in: phpMyAdmin SQL query
-- Update Focus Keywords (sets post_title as focus keyword)
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_yoast_wpseo_focuskw', post_title FROM wp_posts WHERE post_type = 'post';
-- Update Readability Score (47 = green)
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_yoast_wpseo_content_score', 47 FROM wp_posts WHERE post_type = 'post';
-- Update SEO Score (47 = green)
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_yoast_wpseo_linkdex', 47 FROM wp_posts WHERE post_type = 'post';
WordPress
Create WordPress admin via phpMyAdmin
Goes in: phpMyAdmin — wp_users & wp_usermeta tables
1. Copy any existing user row in wp_users table
2. Note the new user's ID
3. Go to wp_usermeta table
4. Copy these meta_key rows for the new user ID:
- 'wp_capabilities' → value: a:1:{s:13:"administrator";b:1;}
- 'wp_user_level' → value: 10
5. Update 'user_id' to the new user's ID on both rows
.htaccess
.htaccess reference — common codes
Goes in: .htaccess file
# Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com [nc]
RewriteRule ^(.*)$ http://www.test.com/$1 [r=301,nc]
# 301 redirect single file
Redirect 301 /old-page.php /new-page.php
# 301 redirect entire directory
RedirectMatch 301 /old-dir(.*) /new-dir/$1
# Cache static assets
<FilesMatch "\.(jpg|css|js)$">
Header set Cache-Control "private, proxy-revalidate, max-age=5400"
</FilesMatch>
# Password protect directory
<Files /admin>
AuthName "Restricted"
AuthType Basic
AuthUserFile /.htpasswd
Require valid-user
</Files>
# Block hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|png|gif)$ - [F,NC,L]
# Custom error pages
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
# Block specific IP
Deny from 123.123.123.123
# Prevent directory listing
Options All -Indexes
# Prevent viewing .htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>
PHP
Show different content for bots vs users
Goes in: PHP template file
<?php
if ($_SERVER['REQUEST_URI'] == '/your-page/') {
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false) {
echo 'Content for Googlebot';
} else {
echo 'Content for regular users';
}
}
?>
Shopify
Show code on specific pages (Liquid)
Goes in: layout/theme.liquid or where required
{% if request.path contains '/products/' %}
<!-- Product page code here -->
{% elsif request.path contains '/collections/' %}
<!-- Collection page code here -->
{% elsif product.title == 'Specific Product Name' %}
<!-- Specific product code here -->
{% else %}
<!-- Default code here -->
{% endif %}
Shopify
Exclude specific URL from XML sitemap
Goes in: Shopify Admin → Settings → Metafields
1. Go to Settings > Metafields in your Shopify admin
2. Click the category (e.g. Collections, Pages, Products)
3. Click "Add definition" with these settings:
- Name: Hide from XML Sitemap
- Namespace & key: seo.hidden
- Check "Expose this metafield to the storefront"
- Content type: Number → Integer
4. Click Save
To hide a specific page:
1. Edit the page/product
2. Set "Hide from XML Sitemap" metafield value to: 1
3. Save
Other
Search Console: Regex to filter keyword groups
Goes in: Search Console → Performance → Filter Queries
# Match "tool" or "tools" or "software" or "softwares"
\b(?:tool|software)s?\b
# Match exact phrase
^exact phrase here$
# Match URL pattern
/blog/.*
WordPress
Bulk update Yoast titles & descriptions from CSV
Goes in: Create PHP script at WordPress root, upload CSV, run via browser
<?php
// File: update-meta.php at WordPress root
// CSV format: URL,Title,Description (no headers)
// Run once then delete the file!
require_once('wp-load.php');
function update_meta_from_csv($csv_path) {
if (($handle = fopen($csv_path, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {
$url = $data[0];
$new_title = isset($data[1]) ? $data[1] : '';
$new_description = isset($data[2]) ? $data[2] : '';
$page_id = url_to_postid($url);
if ($page_id) {
if (!empty($new_description))
update_post_meta($page_id, '_yoast_wpseo_metadesc', sanitize_text_field($new_description));
if (!empty($new_title))
update_post_meta($page_id, '_yoast_wpseo_title', sanitize_text_field($new_title));
echo "Updated: {$url}<br>";
} else {
echo "Not found: {$url}<br>";
}
}
fclose($handle);
}
}
update_meta_from_csv('descriptions.csv');
Shopify
Bulk editor URL shortcuts
Goes in: Browser URL bar — replace {Store-ID} with your store ID
# Bulk edit Collections
https://admin.shopify.com/store/{Store-ID}/admin/bulk?resource_name=Collection&fields=title,seo.hidden
# Bulk edit Products
https://admin.shopify.com/store/{Store-ID}/bulk/product?resource_name=Product
# Bulk edit Pages
https://admin.shopify.com/store/{Store-ID}/admin/bulk?resource_name=Page&fields=title,body_html,published_at
No snippet matches that. Try a shorter search.