TL;DR
mod_rewrite
is loaded.htaccess
is writableAllowOverride ALL
is setLogLevel debug
is setThe WordPress blog is located in filesystem location /var/www/html/
(i.e. index.php
is in there, as are all the wp-*.php
files such as wp-settings.php
).
The WordPress blog's General Settings for WordPress Address (URL) and Site Address (URL) are both set to https://example.com/blog
.
When I set the Permalink Settings to Month and name (or anything other than Plain), the .htaccess
file is automatically modified to contain the following mod_rewrite
block, and the URL paths adjust accordingly, e.g. /blog/2019/03/hello-world/
, yet the accessing the URLs results in an Internal Server Error.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
The log reveals the following:
Request exceeded the limit of 10 internal redirects due to probable configuration error.
AH00121: r->uri = /blog/index.php, referer: https://staging.example.com/blog/
AH00122: redirected from r->uri = /blog/index.php, referer: https://staging.example.com/blog/
... the above line repeated ...
AH00122: redirected from r->uri = /2019/03/10/hello-world/, referer: https://staging.example.com/blog/
With the Permalink Settings set to Plain, the .htaccess
file is essentially empty, and the links work, though they are of the undesirable form /?p=123
:
# BEGIN WordPress
# END WordPress
When I set Custom Structure, to /index.php/%year%/%monthnum%/%postname%/
, the blog links are updated to the format /blog/index.php/2019/03/hello-world/
and they work, but now the URL is ugly (the /index.php/
).
So why doesn't it work with /%year%/%monthnum%/%postname%/
and the automatically set .htaccess
directives?
gory details
It shouldn't matter, but for the record: this WordPress blog is hosted in a Virtual Machine instance (VM instance) of the Compute Engine of Google Cloud Platform.
Remove /blog
from the last rule (RewriteBase
stays as before).
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress