• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Rewrite Rules - Apache to Nginx

Fred.

Well-known member
#1
Hi,

Can someone please help me out. I'm trying to find this out for 3 days now :confused:
I'm moving from Apache to Nginx.

These are my apache rewrite rules.

Code:
# vBSEO to XF
RewriteEngine on

RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.example\.com$
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com$1 [R=301,L]

RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
RewriteRule ^members/([^\.]+)\.html$ /member_redirect.php?username=$1 [R=301,L]

RewriteRule ^algemeen/$ /forums/algemeen.29/ [R=301,L]

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>
And this is what I have for nginx.
Xenforo is working but my old vbulletin url's are not. The url redirection scripts are in place.
I get
Error
Route algemeen/6349-thread-title.html could not be found.


Code:
rewrite ^(.*)$ https://$server_name$1 permanent;

location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    index index.php index.html;
}

location /internal_data/ {
    internal;
}
location /library/ {
       internal;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include         fastcgi_params;
}

# vBulletin-VBSEO to XenForo RR

rewrite /[^/]+/([d]+)-.+-([d]+).html /showthread.php?t=$1&page=$2 last;
    rewrite /[^/]+/([d]+)-.+.html /showthread.php?t=$1 last;
    rewrite ^/members/([^.]+).html$ /member_redirect.php?username=$1 permanent;
    rewrite ^/algemeen/$ /forums/algemeen.29/ permanent;
Thanks! :)
 

Fred.

Well-known member
#2
I think I got it...
The threads are working now.
I replaced these rules
Code:
rewrite /[^/]+/([d]+)-.+-([d]+).html /showthread.php?t=$1&page=$2 last;
    rewrite /[^/]+/([d]+)-.+.html /showthread.php?t=$1 last;
by this
Code:
        rewrite [^/]+/([0-9]+)-.+-([0-9]+)\.html /showthread.php?t=$1&page=$2 last;
    rewrite [^/]+/([0-9]+)-.+\.html /showthread.php?t=$1 last;
The only thing I see now is that thread / forum paging isn't working. And is seems like it wasn't working with my apache rules ether :eek:
Does anyone know how I can fix this?
 

Tower

Active member
#3
Code:
# redirect from non-www to www
# uncomment, save file and restart Nginx to enable
#server {
#            listen   80;
#            server_name example.com;
#            return 301 $scheme://www.example.com$request_uri;
#       }

server {
  server_name example.com www.example.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/example.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/example.com/log/error.log;

  root /home/nginx/domains/example.com/public;

   location /forums/ {
            index index.php index.html index.htm;
            try_files $uri $uri/ /forums/index.php?$uri&$args;

        }

        location /forums/internal_data/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

        location /forums/library/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}
This is what I use WITHOUT a forums directory