I am using the official WordPress image with Apache and can confirm that the htaccess file in the container is being used because I can cause an Server Errror with incorrect code.
All seems well apart from the Yoast SEO plugin - the XML sitemap just will not show up as expected.
I have read this official help page and checked it all…
…but it does not work for me.
Here is an extract of the Docker Compose file which shows the volume mount…
# Yoast SEO - XML Sitemap Rewrite Fix
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 [L]
</IfModule>
# END Yoast SEO - XML Sitemap Rewrite Fix
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
…but the SEO Sitemap part is ignored.
Can anyone help to get this working or is this a known limitation of Docker WordPress?
It was years ago when I had to write htaccess rules, so I can’t give you a 100% sure answer, but I don’t think that the SEO section is ignored. I think it is just overridden in the next section.
Try to add more conditions using RewriteCond to the second section so it will not rewrite the path when the requests starts with the filenames from the first section.
If I am right, then this is not related to Docker and it is not even a “limitation” of WordPress. It is just how Rewrite rules work. I remember I had some hard time to figure similar rules out.
Oh, that’s just been changed back by WordPress automatically, which is why Yoast said to add it before as a separate code block.
I think I need to ask Yoast themselves for help on this.
Either that, or change to not use Docker but MariaDB and NginX instead - on which I know XML sitemaps work…
I think it would be good for the Docker community to fix this problem though… I am sure plenty of other companies use Docker WordPress in their production web sites and need the SEO XML Sitemaps working!
Okay, I think I didn’t see the whole picture here and I also read your post too quickly. Now I understand “Yoast SEO plugin” is Wordpress plugin which is what you indeed wrote at the beginning. Since you shared a link I went there and I saw the additional part in the .htaccess file thinking that you added it manually. If you did, I think you should not have done it. If you just activated the SEO plugin which regenerated the .htaccess file, that should have worked. I installed the latest Wordpress from the official Docker image, then I activated “permalink” in the settings (I changed from “plain” to “post name”. After that I installed Yoast SEO plugin and tried to load http://localhost:8080/sitemap_index.xml. It worked.
I even tried to change permalinks back to “Plain” and the sitemap still worked.
So it looks like I was wrong. The htaccess rules are good so I don’t know why it didn’t work for you.
Yes. It is also in the comments but I missed that part too…
I just realized The description of the official Docker image for Wordpress mentions that the image is maintained by the “Docker Community”, but I don’t know which part of the community and whether the developers are here on the “Community Forum”. Maybe an older member could tell that.
So if you think the image needs some improvement, the best place to ask for it may be the GitHub repository in a new issue.
My personal opinion is that WordPress does not make it easier to create really a good Docker image for the CMS. For example: because it writes the .htaccess, it needs to have permission to write the document root, which is not a good idea. Containerizing an application is not always just putting it inside a container
However, in this case, I think we should find out why this Yoast SEO plugin works for me, but not for you. The only difference I can see between our coniguration is that I did not mounted the document root. I just run the example from the Docker image description
The only difference I can see with the live ‘problem’ site is the Permalink structure - which is on /%category%/%postname%/ instead of just /%postname%/
…and sure enough, if I change the test site I have just created to the same Permalink structure of /%category%/%postname%/ then it gives the error of 404.
Ah ha - we have found the cause of the error!
How can I keep the /%category%/%postname%/ permalink structure and use Yoast XML Sitemaps?
Can you try that same change on your test site please?
I tried it with a custom permalink structure using category and postname. The result is the same. It works. I also tried to access sitemap.xml because you mentioned. I thought it was mistake and you meant sitemap_index.xml but it redirected to sitemap_index.xml even in a different browser. Now the there is an other differnce between our configs. I don’t use nginx proxy