WordPress Blog Setup via Softaculous (cPanel)
Main Domain: domain.com
Blog URL: www.domain.com/blog/
Subdomain: blog.domain.com
1. Add DNS Record for Subdomain
Before doing anything in cPanel, make sure the subdomain points to your hosting server:
- Go to your DNS Zone Manager (domain registrar or cPanel β Zone Editor).
- Add an A Record:
- Name:
blog.domain.com - Type:
A - Value: your hosting serverβs IP Address
- Name:
π After propagation, blog.domain.com will point to your hosting account.
2. Create Subdomain in cPanel
- Log in to cPanel.
- Go to Domains β Subdomains.
- Create a subdomain:
- Subdomain:
blog.domain.com - Root Directory:
public_html
- Subdomain:
π This ensures blog.domain.com points to your hosting root.
3. Install WordPress Using Softaculous
- In cPanel, go to Softaculous Apps Installer β WordPress.
- Click Install Now.
- Choose settings:
- Choose Domain: select your main domain
domain.com(not the subdomain). - In Directory: enter
blog
(this means WordPress will be installed inpublic_html/blog).
- Choose Domain: select your main domain
- Fill out site details, admin user, password, and email.
- Click Install.
β WordPress is now installed at domain.com/blog.
4. Update WordPress URLs
Once installation finishes:
- Log in to WordPress Dashboard β Settings β General. Or You can update via database in wp-options table
- Update:
- WordPress Address (URL):
https://www.domain.com/blog - Site Address (URL):
https://www.domain.com/blog
- WordPress Address (URL):
- Save changes.
5. Replace .htaccess in Root (public_html)
Go to public_html/.htaccess and replace with:
# BEGIN WordPress
# Custom redirect: Force all traffic to /blog
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Redirect everything except already in /blog
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ /blog/$1 [L]
</IfModule>
# END WordPress
6. Modify wp-blog-header.php in /blog
Open public_html/blog/wp-blog-header.php and replace with:
This code is for custom redirect logic: Ensures all traffic goes to https://www.domain.com/blog
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
$path = str_replace("/blog","",$_SERVER['REQUEST_URI']);
if($_SERVER['HTTP_X_ACCESS_FROM_SUBDOMAIN'] == null || $_SERVER['HTTP_X_ACCESS_FROM_SUBDOMAIN'] != "true")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.domain.com/blog{$path}");
exit;
}
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
β Final Behavior
domain.com/blogβ 301 redirect βwww.domain.com/blogblog.domain.comβ 301 redirect βwww.domain.com/blogwww.domain.com/blogβ β Blog loads correctly