• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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