I have the following problem: I made 10 WordPress sites for 1one client and now he needs me to configure the domains in his VPS.

Based on some searches I did on the internet, the first thing I needed to do was create a new file of configuration within /etc/apache2/sites-available and enable it with a2ensite. Perfect! I did it and it was as follows for each site:

<VirtualHost *:80>
    ServerAdmin (my email)
    ServerName (configured domain)
    ServerAlias (configured domain)
    DocumentRoot /var/www/html/10_sites/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/html/10_sites>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

My .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteBase /10_sites/
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

</IfModule>

After that, I had to go to the websites and change the website address, I went there and changed it to the correct address.

After enabling the 2 configurations it worked as I wanted today it opens the site in the domain. So theoretically everything would be right.

But then I came across a problem, when I open the site and I go to the administrative area (/wp-admin) and I try to login it says:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at (my email) to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

1 Answer
1

it opens the site in the domain

Have you tested inner pages, not just the homepage?

A seeming inconsistency in your config is that you have defined DocumentRoot /var/www/html/10_sites/ in your vHost(s) yet you have set RewriteBase /10_sites/ in your .htaccess file.

Unless your site files are located in /var/www/html/10_sites/10_sites/ (yes, the last directory repeated twice) then you will get a rewrite-loop (500 Internal Server Error) for any requests other than the homepage (including /wp-admin pages), since index.php will not be found.

Requests for the homepage, ie. http://example.com/, will work OK since this does not rely on the mod_rewrite directives in .htaccess to route the request to index.php. Instead, this is handled by mod_dir and the DirectoryIndex.

I did it and it was as follows for each site:

However, there are other inconsistencies with your config…

If you are using WordPress multisite (as implied by your .htaccess file) then you should not be defining a vHost for each domain (at least there is no need to unless you specifically need separate log files from the get go*1 or to perhaps customise the config per domain – neither of which is suggested by your config). You would simply include a ServerAlias for each domain. (There is no need to define ServerName and ServerAlias the same – as implied by your config.)

(*1 The config you posted implies you are using a single access and error log for all domains. This is more performant than using separate log files for each domain, however, you need to customise the log format to include the requested hostname (which you have not done). Otherwise, you will not be able to split the logs later.)

But if you are not using WP multisite then you shouldn’t be defining the same vHost for each domain (as implied by your <VirtualHost> config).

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *