0

Background

As someone who develops multiple websites I wanted to be able to serve each site from within its respective project folder in the filesystem, instead of serving them all under the htdocs directory.

So I moved my wordpress folder (whose site was usually accessed via localhost/wordpress) to my project directory, and followed the instructions in this answer to set up a virtual host with a DocumentRoot and Directory that matches the new location of the wordpress folder. This is the whole (uncommented portion) of my httpd-vhosts.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress"
    ServerName localhost.irm
    <Directory "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress">
    Options FollowSymLinks 
    AllowOverride All
        Require all granted  
    </Directory>
</VirtualHost>

The Problem

The homepage can now be found at localhost.irm, but it's text-only, with no styles or images, and clicking on any page takes me to an "Object not found!" XAMPP page.

What I've Tried

  • Accessed the database with PHPMyAdmin, changing siteurl and home in the wp_options table to reflect the new domain

  • Used the WP-CLI tool to search-and-replace all database instances of the old domain with the new one

Unfortunately none of these solved the problem.

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
  • 1
    You did not happen to forget to include the part `http://` in your `siteurl` and `home`? – Dirk J. Faber Nov 13 '20 at 21:04
  • @DirkJ.Faber Good shout, but I did include it, and tried both `http` and `https`. – Hashim Aziz Nov 13 '20 at 22:25
  • You restarted Apache? I can't see anything wrong with your code really. – Dirk J. Faber Nov 13 '20 at 22:29
  • Yep, must have restarted hundreds of times trying to solve this issue over the last few days. So to confirm, what I'm trying to do - serve my sites outside of `htdocs` - should be possible? – Hashim Aziz Nov 13 '20 at 22:40
  • 1
    Yes this is possible and should not be a problem. Here's a suggestion: try running the PHP's built in server so you'll know if the problem has to do anything with Apache or not. Open a terminal (like Git Bash for example), navigate to your sites root directory and type: `php -S localhost.irm:80`. Now check your website in the browser by going to `localhost.irm`. – Dirk J. Faber Nov 13 '20 at 22:43
  • Nope, same result. – Hashim Aziz Nov 13 '20 at 22:55
  • This means your issue is not with Apache, but with either your Wordpress settings or in your code. I would check `wp-config.php` to see if you happen to have `WP_HOME` or `WP_SITEURL` defined there and check `index.php`. Otherwise, I do not know. – Dirk J. Faber Nov 13 '20 at 23:02
  • @Dirk J. Faber Okay, I've made some progress. I deactivated the SG-cachepress plugin using `wp-cli` - I wasn't even aware that it was still active, but apparently that was rewriting my http to https and causing the lack of styling as well as the "Object not found" error. The homepage now looks as it should - now the only problem is that accessing other (now http) pages gives me an "Internal Server Error". – Hashim Aziz Nov 13 '20 at 23:06
  • I have a feeling that my self-signed SSL certificate may need renewing after the move, so I'll try and regenerate it and see if it fixes the issue. – Hashim Aziz Nov 13 '20 at 23:07

1 Answers1

0

This seemed to be primarily caused by two problems:

  1. The Site Ground Optimiser plugin from my live site that I wasn't even aware was activated on my local site. Deactivating using wp plugin deactivate sg-cachepress (the WP-CLI tool) solved that.

  2. The following line in my .htaccess file, at the root of my Wordpress site:

    RewriteBase /wordpress/ 
    

    I assume it must have been necessary to add for my previous setup and I'd since forgotten about it. Either way, removing/commenting the line out entirely seems to have solved the rest of the problem.

I'm now able to access my website with all styles and images, just like I was before, with the advantage that my files are now being served from my project folder itself instead of from XAMPP\htdocs.

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68