# Rewrite rules

**URL:** <https://www.ruby-forum.com/t/rewrite-rules/127408>\
**Category:** NGINX\
**Created:** [January 28, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/rewrite-rules/127408 "2008-01-28T23:00:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_SSSSlusarczyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@Jan\_SSSSlusarczyk](https://www.ruby-forum.com/u/Jan_SSSSlusarczyk)\
**Post date:** [January 28, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/rewrite-rules/127408/1 "2008-01-28T23:00:45Z")

</div>

I’m trying to move my vbulletin forum to nginx+fastcgi php. The  
traffic is killing apache2. The only thing left is rewrite rule for  
vbseo. I’ve been trying to convert them myself, but I have to give up  
and ask for your help. These are the rules:

RewriteRule ^((urllist|sitemap\_).\*.(xml|txt)(.gz)?)$ vbseo\_sitemap/  
vbseo\_getsitemap.php?sitemap=$1 [L]

RewriteCond %{QUERY\_STRING} !vbseourl=  
RewriteCond %{REQUEST\_URI} !(admincp/|modcp/|chat|cron)  
RewriteRule ^(._.php(/._)?)$ vbseo.php?vbseourl=$1 [L,QSA]

RewriteCond %{REQUEST\_FILENAME} !.(jpg|gif)$  
RewriteRule ^(archive/.\*)$ vbseo.php?vbseourl=$1 [L,QSA]

RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !^(admincp|modcp|clientscript|cpstyles|  
images)/  
RewriteRule ^(.+)$ vbseo.php?vbseourl=$1 [L,QSA]

Any help will be very appreciated. I will include the working code on  
Wiki for other users…

Thanks  
Jan

---

<div class="post-metadata">

**Author:** ![Jan\_SSSSlusarczyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@Jan\_SSSSlusarczyk](https://www.ruby-forum.com/u/Jan_SSSSlusarczyk)\
**Post date:** [January 28, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/rewrite-rules/127408/2 "2008-01-28T23:59:37Z")

</div>

I would start with something like this:

location ~\*  
^.+.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$  
{  
root /home/vbseo/public\_html;  
rewrite  
^/archive/(.\*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$  
/vbseo.php?vbseourl=$1 last;  
expires 10d;  
break;  
}

location / {  
root /home/vbseo/public\_html;  
index index.php;  
if (!-e $request\_filename) {  
rewrite ^(.+)$ /vbseo.php?vbseourl=$1 last;  
}

---

<div class="post-metadata">

**Author:** ![Jan\_SSSSlusarczyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@Jan\_SSSSlusarczyk](https://www.ruby-forum.com/u/Jan_SSSSlusarczyk)\
**Post date:** [January 31, 2008, 2:40pm UTC](https://www.ruby-forum.com/t/rewrite-rules/127408/3 "2008-01-31T14:40:19Z")

</div>

> 

Thanks for all the tips. For a combination of Typo3 installation on  
root (realurl rewriting to /index.php) and vbseo enhanced vbulletin  
in /forum/ directory of a main site I’ve come up with the following:

server {  
listen 192.168.1.1:80;  
server\_name www.servername.tld;  
access\_log /var/log/nginx/www.servername.tld.access.log combined;

root /var/www/hosts/www.servername.tld;  
index index.php index.html index.htm;

location ~ /.ht {  
deny all;  
}  
location /forum/ {  
rewrite ^/forum/((urllist|sitemap\_)._.(xml|txt)(.gz)?)$ /forum/  
vbseo\_sitemap/vbseo\_getsitemap.php?sitemap=$1 last;  
if ($request\_filename ~ “.php$” ) {  
rewrite ^(._)$ /forum/vbseo.php?vbseourl=$1 last;  
}  
if (!-e $request\_filename) {  
rewrite ^/forum/(._)$ /forum/vbseo.php?vbseourl=$1 last;  
}  
}  
location / {  
if (!-e $request\_filename) {  
rewrite ^(._)$ /index.php last;  
}  
}  
location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME  
/var/www/hosts/www.servername.tld  
$fastcgi\_script\_name;  
include /etc/nginx/fastcgi.conf;  
}  
}

Does it make sense? Can it be better? Anything I should be aware of?  
Thank you  
Jan

---

<div class="post-metadata">

**Author:** ![Jan\_SSSSlusarczyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@Jan\_SSSSlusarczyk](https://www.ruby-forum.com/u/Jan_SSSSlusarczyk)\
**Post date:** [February 6, 2008, 12:09am UTC](https://www.ruby-forum.com/t/rewrite-rules/127408/4 "2008-02-06T00:09:13Z")

</div>

I am attempting to use vBSEO with nginx as well. Your rules work great  
except image attachments currently aren’t working. I believe vBSEO  
rewrites attachment URLs in Apache as well, but there aren’t any  
applicable nginx rewrites active in the conf you posted.

Do you have any idea what might get them working (are they working for  
you)?

Jan Åšlusarczyk wrote:

> ```
> root /var/www/hosts/www.servername.tld;
> }
> fastcgi_pass 127.0.0.1:9000;
> 
> ```

–

Andrew Hunn (Boethius)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
