As MrWhite suggested the following steps solved the issues:
1) Adding vhost block to apache2.conf configuration file of Apache.
NameVirtualHost 192.168.1.10:80
<VirtualHost 192.168.1.10:80>
ServerName local.site.com
DocumentRoot "/var/www/html/local.site"
</VirtualHost>
- /var/www/html/local.site is the folder on local machine where all the website files are.
- local.site.com is the domain name of the local website
- VirtualHost directive has an explicit IP address discoverable by running ip addr show in the command line to support multiple name-based virtual hosts on one ip address
2) Adding the following entry to /etc/hosts
192.168.1.10 local.site.com
To conform to note here
Creating virtual host configurations on your Apache server does not
magically cause DNS entries to be created for those host names. You
must have the names in DNS, resolving to your IP address, or nobody
else will be able to see your web site. You can put entries in your
hosts file for local testing, but that will work only from the machine
with those hosts entries.
3) Using the same .htaccess from the staging website
It basically contains the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
There may be much more directives originating from security wordpress plugins. If they use staging website url like in:
#AIOWPS_PREVENT_IMAGE_HOTLINKS_START
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://site.com [NC]
RewriteRule \.(gif|jpe?g?|png)$ - [F,NC,L]
</IfModule>
RewriteCond %{HTTP_REFERER} !^http(s)?://site.com [NC]
should be replaced with RewriteCond %{HTTP_REFERER} !^http(s)?://local.site.com [NC]
All the steps were run after:
Cloning site code repository to local development environment
Importing mysql dump to local mysql db
- Using wp-cli to
search and replace staging site url with local.site.com