Multisite without .htaccess

Do I need to use .htaccess file for a multisite? I have setup basic wordpress site and configured it with apache2 VirtualHost as:

<VirtualHost *:80>
    ...
    RewriteEngine On
    Options FollowSymLinks

    # THIS REDIRECTS TO HTTPS
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    DocumentRoot /var/www/example/
    <Directory /var/www/example/>
       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order allow,deny
       allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:443>
    ...
    DocumentRoot /var/www/example/
    <Directory /var/www/example/>
       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order allow,deny
       allow from all
    </Directory>

    SSLEngine on

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>

However, when I follow the steps to enable multisite, wordpress prompts me to paste these options to my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

But I do not have an .htaccess file. However If I make it, and configure apache, rewrite rules do not work, e.g. example.com/wp-admin is not rewritten into wp-admin/ with a trailing slash, but into ugly long link: https://example.com/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fwp-admin%2F&reauth=1. Can this be because of SSL rewrite rules? My questions are: do I need .htaccess? And how do I make its rewrite rules work?

1 Answer
1

e.g. wpinstance.com/wp-admin is not rewritten into wp-admin/ with a trailing slash, but into ugly long link: https://wpinstance.com/wp-login.php?redirect_to=https%3A%2F%2Fwpinstance.com%2Fwp-admin%2F&reauth=1

As is already mentioned in comments, this is intentional. There is no “pretty” URL for this. And neither does there need to be – this should not be indexed or linked to.

do I need .htaccess?

No, you don’t “need” .htaccess.

If you have access to the server config, then you can paste these directives verbatim inside the <Directory /var/www/wpinstance/> container (inside the <VirtualHost *:443> container).

However, to paste those directives directly inside the <VirtualHost> container you would need to make several changes, since mod_rewrite behaves differently in a server context (as opposed to a directory or .htaccess context).

Note that everytime you make changes to the server config then you will need to restart Apache. You don’t need to restart Apache when you change the .htaccess file.

I would also consider disabling MultiViews – unless you specifically require this for something? ie. Remove MultiViews from the Options directive. (MultiViews can conflict with mod_rewrite – depends what you are doing.)

If you are not going to use .htaccess files then they should be disabled:

AllowOverride None

UPDATE:

I’m using Apache/2.4.18

Note that the Order and Allow directives are deprecated in Apache 2.4, and will be removed in future versions. You need to change the following (Apache 2.2 and earlier) directives:

Order allow,deny
Allow from all

to read:

Require all granted

in Apache 2.4+

Leave a Comment