• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question NGINX Rewrite Problem on Wordpress

abotis

New Pleskian
Hi everyone,

A kind of strange problem: Wordpress subpages works with and without trailing slash.
They should always end with a trailing slash (Wordrpess do this already, but it's possbile to enter the same page without the slash).

Here my additional nginx directives:

Code:
fastcgi_read_timeout 300;

gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

if (!-e $request_filename) { rewrite ^(.*)$ /index.php?q=$1 last; break; }

if ($request_uri !~ "^/wp-json") { rewrite ^([^.]*[^/])$ $1/ permanent; }
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# try_files in locations is required to pre-empt the above rewrite

# Security directives of iThemes Security
include "/var/www/vhosts/website.url/nginx.conf";
include "/var/www/vhosts/website.url/wp-content/uploads/wpseo-redirects/.redirects";

# Now the generic stuff which is good for all PHP sites

location = /nginx.conf { deny all; }

location ~* \.(txt)$ { charset utf-8; }

# Pics and Fonts valid 90 Days in Cache
location ~* \.(png|jpg|jpeg|gif|ico|bmp|img|ttf|otf|eot|svg|woff|webp)$ {
    expires 4w;
    add_header Pragma public;
    add_header Cache-Control public;
    try_files $uri @fallback;
}

# Zips + PDF valid 4 weeks in Cache
location ~* \.(bz2|exe|gz|pdf|rar||tgz|zip)$ {
    expires 4w;
    add_header Pragma public;
    add_header Cache-Control public;
    try_files $uri @fallback;
}

# Media files (large) valid 2 months in Cache
location ~* \.(ac3|avi|flv|iso|mp3|mp4|mpeg|mpg|ogg|qt|rm|swf|wav)$ {
    expires 2m;
    add_header Pragma public;
    add_header Cache-Control public;
    try_files $uri @fallback;
}

# Possibly modified content valid 1 week in Cache
location ~* \.(js|css|htm|html|xhtml|xml|dat|doc|docx|dts|ppt|pptx|tar|txt|xls|xlsx)$ {
    expires 1w;
    add_header Pragma public;
    add_header Cache-Control public;
    try_files $uri @fallback;
}

PHP 7.2.10 cofigured as FPM served by NGINX.
 
I think I understand what you want better now. Let me recap:

  • /test should show the contents of /test/index.html
  • /test/ should redirect to /test
  • /test/index.html should redirect to /test
  • /test/something.html should show its own contents
You can do this with the knowledge that I gained by asking about how to do something similar here: How to rewrite to a script and also redirect away from that script using .htaccess while avoiding infinite loops

This is what you can put in .htaccess that should work for you:

DirectorySlash Off
RewriteEngine on

RewriteRule ^test$ /test/index.html [L,E=LOOP:1]

RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^test/$ /test [R=301,L]

RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^test/index.html$ /test [R=301,L]

I tested this on my server, it satisfies all the conditions that I outlined above when I have a /test/ directory containing the files index.html and something.html

For javascript, tutorials click here
 
Thanks for help and your reply. And sorry, my question wasn't specific:

Right now, Wordpress create /[test]/ permalinks, but it's also possible to reach the site via /test manually

Si i would like to redirect all /[test] permalinks to /[test]/
 
Back
Top