Welcome! Log In Create A New Profile

Advanced

htaccess to nginx rewrite rules

Posted by sipiatti 
htaccess to nginx rewrite rules
June 09, 2009 07:03AM
Hi,

I have this rewriting rules for a vbulletin forum link modul:
[code]
Options +FollowSymlinks
RewriteEngine On

#RewriteBase /links

RewriteRule ^([a-zA-Z_0-9\-]+)/robots\.txt$ robots.txt [QSA,L]
RewriteRule ^whatsnew/links/([0-9]+)/page([0-9]+).html$ browselinks.php?do=newlinks&cutoffdate=$1&page=$2 [QSA,L]
RewriteRule ^whatsnew/links/(([0-9]?|-)+/?)$ browselinks.php?do=newlinks&cutoffdate=$1 [QSA,L]
RewriteRule ^whatsnew/posts/([0-9]+)/page([0-9]+).html$ browselinks.php?do=newposts&cutoffdate=$1&page=$2 [QSA,L]
RewriteRule ^whatsnew/posts/(([0-9]?|-)+/?)$ browselinks.php?do=newposts&cutoffdate=$1 [QSA,L]
RewriteRule ^whatspopular/([a-zA-Z_0-9\-]+)/$ browselinks.php?do=poplinks&orderby=$1 [QSA,L]
RewriteRule ^members/([a-zA-Z_0-9\-]+)/page([0-9]+).html$ browselinks.php?do=member&userrewrite=$1&page=$2 [QSA,L]
RewriteRule ^members/(([a-zA-Z_0-9]|-)+/?)$ browselinks.php?do=member&userrewrite=$1 [QSA,L]
RewriteRule ^([a-zA-Z_0-9\-]+)/(([a-zA-Z0-9]|-)+)/?$ showlink.php?linkrewrite=$2&catrewrite=$1 [QSA,L]
RewriteRule ^([a-zA-Z_0-9\-]+)/([a-zA-Z0-9\-]+)/page([0-9]+).html$ showlink.php?linkrewrite=$2&catrewrite=$1&page=$3 [QSA,L]
RewriteRule ^([a-zA-Z_0-9\-]+)/page([0-9]+).html$ browselinks.php?catrewrite=$1&page=$2 [QSA,L]
RewriteRule ^([a-zA-Z_0-9\-]+)/?$ browselinks.php?catrewrite=$1 [QSA,L]
[/code]


I read all the nginx docs about rewriting and made the followings:
[code]
location /links {
rewrite ^([a-zA-Z_0-9\-]+)/robots\.txt$ /links/robots.txt break;
rewrite ^/links/whatsnew/links/([0-9]+)/page([0-9]+)\.html$ /links/browselinks.php?do=newlinks&cutoffdate=$1&page=$2 break;
rewrite ^/links/whatsnew/links/(([0-9]?|-)+/?)$ /links/browselinks.php?do=newlinks&cutoffdate=$1 break;
rewrite ^/links/whatsnew/posts/([0-9]+)/page([0-9]+)\.html$ /links/browselinks.php?do=newposts&cutoffdate=$1&page=$2 break;
rewrite ^/links/whatsnew/posts/(([0-9]?|-)+/?)$ /links/browselinks.php?do=newposts&cutoffdate=$1 break;
rewrite ^/links/whatspopular/([a-zA-Z_0-9\-]+)/$ /links/browselinks.php?do=poplinks&orderby=$1 break;
rewrite ^/links/members/([a-zA-Z_0-9\-]+)/page([0-9]+)\.html$ /links/browselinks.php?do=member&userrewrite=$1&page=$2 break;
rewrite ^/links/members/(([a-zA-Z_0-9]|-)+/?)$ /links/browselinks.php?do=member&userrewrite=$1 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/(([a-zA-Z0-9]|-)+)/?$ /links/showlink.php?linkrewrite=$2&catrewrite=$1 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/([a-zA-Z0-9\-]+)/page([0-9]+).html$ /links/showlink.php?linkrewrite=$2&catrewrite=$1&page=$3 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/page([0-9]+)\.html$ /links/browselinks.php?catrewrite=$1&page=$2 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/?$ /links/browselinks.php?catrewrite=$1 break;
}
[/code]

but it does not work :(
what could be the problem?
Re: htaccess to nginx rewrite rules
June 09, 2009 09:37AM
Try using "last" instead of "break" in those rules.

--
Jim Ohlstein
Re: htaccess to nginx rewrite rules
June 09, 2009 12:26PM
Thanks I will try. But if a match found there is no need to continue checking the rules, is it?
Anyway from the logic point of view are my rules correct?
Re: htaccess to nginx rewrite rules
June 09, 2009 12:38PM
There are some other rules in the server section, but as I see it won't conflict with my rules. I am really stucked :(
Here is the complete stanza (servername edited to xxxxxx because I am not the owner and need to protect privacy, sorry):
[code]
server {

listen 80;

server_name forum.xxxxxx.info chat.forum.xxxxxx.info forum-new.xxxxxx.info;



root /var/www/www/vbulletin;

index index.php index.html;



error_page 404 /errors/404.html;







rewrite ^/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 break;



if ($request_filename ~ "\.php$" ) {

rewrite ^/(.*)$ /vbseo.php?vbseourl=$1 break;

}



if (!-e $request_filename) {

rewrite ^/(.*)$ /vbseo.php?vbseourl=$1 break;

}



location ~ .svn {

deny all;

}



location ~ \.php(/|$) {

if ($uri ~ ^/images/) {

return 404;

}

include fastcgi_params.jedi;

}



location = /clear.gif {

empty_gif;

expires max;

}



location ~* \.flv$ {

flv;

}



location = /xxx-nginx-status {

stub_status on;

}



location ~ ^/(archive|attachments|ww|cpstyles|customavatars|customprofilepics|fonts|highslide|imgcache|season|signaturepics|galerie|traduction|errors)/ {

expires 1d;

}



location ~ ^/(clientscript|images)/ {

expires 1h;

}



location /events {

expires 5s;

}



location ~* ^/(css|swf)/ {

expires 15m;

}



location /imgcache {

valid_referers none blocked *.xxxxxx.info;

}



location /attachments {

valid_referers none blocked *.xxxxxx.info;

}



location /customavatars {

valid_referers none blocked *.xxxxxx.info;

}

location /links {
########################################################
# rewrite rules made by sipiatti
########################################################
rewrite ^([a-zA-Z_0-9\-]+)/robots\.txt$ /links/robots.txt break;
rewrite ^/links/whatsnew/links/([0-9]+)/page([0-9]+)\.html$ /links/browselinks.php?do=newlinks&cutoffdate=$1&page=$2 break;
rewrite ^/links/whatsnew/links/(([0-9]?|-)+/?)$ /links/browselinks.php?do=newlinks&cutoffdate=$1 break;
rewrite ^/links/whatsnew/posts/([0-9]+)/page([0-9]+)\.html$ /links/browselinks.php?do=newposts&cutoffdate=$1&page=$2 break;
rewrite ^/links/whatsnew/posts/(([0-9]?|-)+/?)$ /links/browselinks.php?do=newposts&cutoffdate=$1 break;
rewrite ^/links/whatspopular/([a-zA-Z_0-9\-]+)/$ /links/browselinks.php?do=poplinks&orderby=$1 break;
rewrite ^/links/members/([a-zA-Z_0-9\-]+)/page([0-9]+)\.html$ /links/browselinks.php?do=member&userrewrite=$1&page=$2 break;
rewrite ^/links/members/(([a-zA-Z_0-9]|-)+/?)$ /links/browselinks.php?do=member&userrewrite=$1 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/(([a-zA-Z0-9]|-)+)/?$ /links/showlink.php?linkrewrite=$2&catrewrite=$1 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/([a-zA-Z0-9\-]+)/page([0-9]+).html$ /links/showlink.php?linkrewrite=$2&catrewrite=$1&page=$3 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/page([0-9]+)\.html$ /links/browselinks.php?catrewrite=$1&page=$2 break;
rewrite ^/links/([a-zA-Z_0-9\-]+)/?$ /links/browselinks.php?catrewrite=$1 break;
########################################################
}



if ($invalid_referer) {

return 403;

}

}
[/code]
Re: htaccess to nginx rewrite rules
June 09, 2009 03:40PM
sipiatti Wrote:
-------------------------------------------------------
> Thanks I will try. But if a match found there is
> no need to continue checking the rules, is it?
> Anyway from the logic point of view are my rules
> correct?

The rewrites appear to be. Try using "last" in the vBSEO rewrites as well.

--
Jim Ohlstein
Re: htaccess to nginx rewrite rules
June 09, 2009 04:05PM
Thanks, I changed them to 'last'. Waiting for the owner to test it...
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 99
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready