K
K
kanuhamru2015-03-18 09:49:55
Nginx
kanuhamru, 2015-03-18 09:49:55

Apache > NGinx rules?

Hello!
Please help me translate these Apache rules into NGinx correctly:

RewriteRule (.+)/feed /$1 [R=301,L]
RewriteRule (.+)/comment-page /$1 [R=301,L]
RewriteRule (.+)/trackback /$1 [R=301,L]
RewriteRule (.+)/comments /$1 [R=301,L]
RewriteRule (.+)/attachment /$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^replytocom= [NC]
RewriteRule (.*) $1? [R=301,L]
RewriteCond %{QUERY_STRING} ^attachment_id= [NC]
RewriteRule (.*) $1? [R=301,L]

RewriteCond %{REQUEST_URI} !^/page/([0-9]+)/$
RewriteRule (.*)/([0-9]+)/$ $1/ [R=301,L]

Or at least explain what they mean?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NO, 2015-03-18
@Mihail9575

It would take a lot of "explaining" in my opinion, so read up on regular expressions in htaccess.
Try:

location ~ /page/([0-9]+)/$ {}

location / {
  rewrite (.+)/feed /$1 redirect;
  rewrite (.+)/comment-page /$1 redirect;
  rewrite (.+)/trackback /$1 redirect;
  rewrite (.+)/comments /$1 redirect;
  rewrite (.+)/attachment /$1 redirect;
  
  if ($query_string ~* "^replytocom=") {
    rewrite ^(.*)$ /$1? redirect;
  }

  if ($query_string ~* "^attachment_id=") {
    rewrite ^(.*)$ /$1? redirect;
  }

  rewrite (.*)/([0-9]+)/$ /$1/ redirect;
}

Read, maybe it will help: wiki.nginx.org/NginxHttpCoreModule#try_files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question