Score:0

Issues with NGINX Rewrite Rules

fr flag

i tried it now several times but it won't work. I have a Server which running Debian 10 with NGINX and Wordpress installed.

Now i need to rewrite some old URLs to the new place.

We must rewrite URLs like this:

example.com/artikel.html?id=##ID##&meldung=###Meldung### to example.com/artikel/$2

server_name example.com www.example.com;
root /var/www/example.com;

index index.html index.htm index.php;
access_log /var/log/nginx/example.com_access.log;
error_log /var/log/nginx/example.com_error.log;
set $skip_cache 0;

# POST requests and URLs with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}

if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php
|sitemap(_index)?.xml") {
set $skip_cache 1;
}

# Don't use the cache for logged-in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass
|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location /Artikel {
rewrite ^/Artikel.html(.*)$ https://example.com/artikel break;
}

location / {
add_header Front-End-Https on;
add_header Cache-Control "public, must-revalidate";
add_header Strict-Transport-Security "max-age=2592000; includeSubdomains";
try_files $uri $uri/ =404 @rewrite;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location @rewrite {
rewrite ^/Artikel.html$ /kontakt permanent;
rewrite ^/Artikel\.html /artikel redirect;
rewrite ^/test/(.*)/$ example2.com/test($1) permanent;
rewrite ^/artikel.html?id=(.*)&meldung=(.*)$ https://example.com/artikel/$2 permanent;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
#fastcgi_cache WORDPRESS;
#fastcgi_cache_valid 60m;
}
#location ^~ /pma/ {
# root /var/www/html/pma;
#}
location ~ /\.ht {
deny all;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
log_not_found off;
}
#location ~ /purge(/.*) {
# fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
#}

# Deny access to uploads that aren’t images, videos, music, etc.
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf)$ {
deny all;
}
# Deny public access to wp-config.php
location ~* wp-config.php {
deny all;
}
location = /robots.txt {
access_log off;
log_not_found off;
}

location ~ /. {
deny all;
access_log off;
log_not_found off;
}
if (!-e $request_filename) {
rewrite ^.* /index.php break;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = example.com.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 8080;
server_name example.com www.example.com;
return 404; # managed by Certbot




}

I looking forward to hear from you soon. Thanks in advance for your efforts.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.