Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Thu Dec 07, 2023 8:31 am


This forum is dedicated to Apache, Nginx, Lighttpd, Squid and other HTTP transport protocol related software

Author Message
debuser
  Post  Post subject: Converting PhpBB-SEO Apache RewriteRule to Nginx rewrite  |  Posted: Tue Feb 23, 2010 5:00 am

Joined: Thu Aug 06, 2009 2:48 am
Posts: 105

Offline
 

Converting PhpBB-SEO Apache RewriteRule to Nginx rewrite

After a few hours of work migrating the phpbb forum from an Apache / prefork / mod_php / mysql (P4 3.2Ghz / 3G RAM) installation to a much slower test system based on Nginx / php-fpm+mysqlnd / mysql (Dual P3 1.2Ghz / 2G RAM), both with xcache and with some compile time optimizations, I was surprised to see the same performance on both systems (ab): ~16 Requests/s. One notable difference is that consecutive Apache tests do not have constant results, while nginx ones do.


Migrating PhpBB-Seo (seo premod forum) from apache to nginx requires, of course, database migration, php files with attachments and last, but not least, rewrite rules migration.

Here is an example of a few Apache RewriteRule for phpbb-seo:
Code:
RewriteRule ^(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$2&t=$4&start=$6 [QSA,L,NC]
# GLOBAL ANNOUNCES WITH VIRTUAL FOLDER ALL MODES
RewriteRule ^announces/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$2&start=$4 [QSA,L,NC]
# TOPIC WITHOUT FORUM ID & DELIM ALL MODES
RewriteRule ^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&s tart=$5 [QSA,L,NC]


and below the equivalent rewrite rules for phpbb-seo in nginx:
Code:
rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$2&t=$4&start=$6 last;
# GLOBAL ANNOUNCES WITH VIRTUAL FOLDER ALL MODES
rewrite ^/announces/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$2&start=$4 last;
# TOPIC WITHOUT FORUM ID & DELIM ALL MODES
rewrite ^/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&start=$5 last;


The trick is to follow these rules:
- RewriteRule becomes rewrite
- in nginx the rewrite rules require a forward slash (/) after the ^ character (in regex it means that the URL should start with a forward slash), while Apache doesn't require this.
Ex.
Code:
^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$
in apache vs.
Code:
^/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$
in nginx
-Following
Code:
[QSA,L,NC]
in apache rewrite rules becomes:
Code:
last;
in Nginx rewrite rules (these must always be terminated by a ; [semicolon]).
- nginx rewrite rules are NOT read from .htaccess files (this should be obvious), but from nginx.conf or from nginx vhost configuration file, depending on your configuration.





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Converting PhpBB-SEO Apache RewriteRule to Nginx rewrite"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Starting nginx: [emerg]: directive "rewrite" is not terminated by ";"

debuser

0

8405

Tue Feb 23, 2010 6:05 am

debuser View the latest post

There are no new unread posts for this topic. Attachment(s) Nginx + apache (for PHP) with real IP addresses in logs

designeru

0

3095

Tue May 18, 2010 9:49 am

designeru View the latest post

There are no new unread posts for this topic. Apache to Nginx Server parameters translation with php function

debuser

0

105131

Thu Aug 26, 2010 7:47 am

debuser View the latest post

There are no new unread posts for this topic. Apache: how to list virtual hosts that are currently configured on my Apache server ?

LaR3

0

4777

Sun Feb 07, 2010 10:04 am

LaR3 View the latest post

There are no new unread posts for this topic. Apache 2.2 installation of mod_rewrite module without recompiling whole apache

debuser

0

6355

Tue Mar 23, 2010 11:22 am

debuser View the latest post

There are no new unread posts for this topic. Phpbb 3.0.5 "Log me on automatically" cookies and sessions problem

debuser

3

10037

Wed May 19, 2010 3:08 am

admin View the latest post

There are no new unread posts for this topic. NGINX: how to set the default virtual host

mandrei99

0

3990

Thu Dec 12, 2013 6:01 am

mandrei99 View the latest post

There are no new unread posts for this topic. Nginx: How to list virtual hosts

mandrei99

0

13335

Mon Feb 23, 2015 5:05 pm

mandrei99 View the latest post

There are no new unread posts for this topic. NGINX: 413 Request Entity Too Large

admin

0

2034

Thu Sep 14, 2017 4:48 am

admin View the latest post

There are no new unread posts for this topic. Nginx + php-fpm increase upload_max_filesize and other php values per vhost

mandrei99

0

8231

Mon Jan 02, 2012 9:04 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 1 guest
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO