# Converting Rewrite rules

**URL:** <https://www.ruby-forum.com/t/converting-rewrite-rules/221030>\
**Category:** NGINX\
**Created:** [June 27, 2012, 11:43pm UTC](https://www.ruby-forum.com/t/converting-rewrite-rules/221030 "2012-06-27T23:43:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 27, 2012, 11:43pm UTC](https://www.ruby-forum.com/t/converting-rewrite-rules/221030/1 "2012-06-27T23:43:06Z")

</div>

I’m needing help on converting a htaccess rules to the nginx format.

I’ve got the software installed in a sub folder called directory. In the  
root of that folder there is this .htaccess information:

#Options +FollowSymLinks  
#Options -MultiViews  
#Options All -Indexes

# This can be uncommented to compress js and css files

#  
#\<FilesMatch “.(js|css)$”\>

# SetOutputFilter DEFLATE

#  
#

# This can be uncommented to set cache control for image, js, and css

files  
#Header unset ETag  
#FileETag None  
#\<FilesMatch “(?i)^.\*.(ico|flv|swf|jpg|jpeg|png|gif|js|css)$”\>  
#Header unset Last-Modified  
#Header set Expires “Fri, 21 Dec 2012 00:00:00 GMT”  
#Header set Cache-Control “public, no-transform”  
#

\<FilesMatch “.(htaccess|tpl)$”\>  
Order Allow,Deny  
Deny from all

RewriteEngine On

#RewriteRule ^([a-zA-Z]+).html$ $1.php [L]

#Handle all category links. Static category text followed by ID,  
followed by path  
#The “category” text here needs to be changed if the language variable  
category is changed  
RewriteRule ^category/(.+/)location/(.+)$  
browse\_categories.php?id=$1&location=$2 [L,NC,QSA]  
RewriteRule ^category/(.+)$ browse\_categories.php?id=$1 [L,NC,QSA]

#Handle all location links. Static location text followed by ID,  
followed by path  
#The “location” text here needs to be changed if the language variable  
location is changed  
RewriteRule ^location/(.+)$ browse\_locations.php?id=$1 [L,NC,QSA]

#Rewrite pages  
RewriteRule ^pages/(.+).html$ page.php?id=$1 [L,NC]

#Rewrite Blog  
RewriteRule ^blog.html$ blog.php [L,NC,QSA]  
RewriteRule ^blog/([^/]+)-([0-9]+).html$ blog\_post.php?id=$2 [L,NC]  
RewriteRule ^blog/category/(.+)-([0-9]+).html$ blog.php?category\_id=$2  
[L,NC,QSA]

#Rewrite listing/banner website out  
RewriteRule ^out-([0-9]+).html$ out.php?listing\_id=$1 [L]  
RewriteRule ^out-([0-9]+)-([0-9]+).html$  
out.php?listing\_id=$1&banner\_id=$2 [L]

#Rewrite listings  
#Ignore any physical files  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^([^/]+).html$ listing.php?id=$1 [L,NC]  
RewriteRule ^([^/]+)/images.html$ listing\_images.php?id=$1 [L,NC]  
RewriteRule ^([^/]+)/send-message.html$ listing\_email.php?id=$1 [L,NC]  
RewriteRule ^([^/]+)/send-message-friend.html$  
listing\_email\_friend.php?id=$1 [L,NC]  
RewriteRule ^([^/]+)/reviews.html$ listing\_reviews.php?id=$1  
[L,NC,QSA]  
RewriteRule ^([^/]+)/add-review.html$ listing\_reviews\_add.php?id=$1  
[L,NC]  
RewriteRule ^([^/]+)/classifieds.html$ listing\_classifieds.php?id=$1  
[L,NC,QSA]  
RewriteRule ^([^/]+)/documents.html$ listing\_documents.php?id=$1  
[L,NC,QSA]  
RewriteRule ^([^/]+)/suggestion.html$ listing\_suggestion.php?id=$1  
[L,NC]  
RewriteRule ^([^/]+)/claim.html$ listing\_claim.php?id=$1 [L,NC]

#Rewrite classifieds  
RewriteRule ^classified/[^/]±([0-9]+).html$ classified.php?id=$1  
[L,NC]  
RewriteRule ^classified/[^/]±([0-9]+)/images.html$  
classified\_images.php?id=$1 [L,NC]

#Rewrite sitemap  
RewriteRule ^sitemap.xml$ xml.php?type=sitemap [L]

RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ 404.php?id=$1 [L,NC]

Then in the following subfolders I’ve got these other ones:

Directory/files  
\<FilesMatch “.(php|php3|php4|phtml|pl|cgi)$”\>  
deny from all

and  
Directory/files/upload

\<FilesMatch “.csv$”\>  
deny from all

and  
Directory/includes/ckeditor

# 

# Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights

reserved.

# For licensing, see LICENSE.html or [CKEditor OSS License](http://ckeditor.com/license)

# 

# 

# On some specific Linux installations you could face problems with

Firefox.

# It could give you errors when loading the editor saying that some

illegal

# characters were found (three strange chars in the beginning of the

file).

# This could happen if you map the .js or .css files to PHP, for

example.

# 

# Those characters are the Byte Order Mask (BOM) of the Unicode encoded

files.

# All FCKeditor files are Unicode encoded.

# 

AddType application/x-javascript .js  
AddType text/css .css

# 

# If PHP is mapped to handle XML files, you could have some issues. The

# following will disable it.

# 

AddType text/xml .xml

This is the converted files I’ve got

# nginx configuration

location /directory/category {  
rewrite ^/category/(.+/)location/(.+)$  
/browse\_categories.php?id=$1&location=$2 break;  
rewrite ^/category/(.+)$ /browse\_categories.php?id=$1 break;  
}

location /directory/location {  
rewrite ^/location/(.+)$ /browse\_locations.php?id=$1 break;  
}

location /directory/pages {  
rewrite ^/pages/(.+).html$ /page.php?id=$1 break;  
}

location = /directory/blog.html {  
rewrite ^(.\*)$ /blog.php break;  
}

location /directory/blog {  
rewrite ^/blog/([^/]+)-([0-9]+).html$ /blog\_post.php?id=$2 break;  
rewrite ^/blog/category/(.+)-([0-9]+).html$ /blog.php?category\_id=$2  
break;  
}

location /directory/out {  
rewrite ^/out-([0-9]+).html$ /out.php?listing\_id=$1 break;  
rewrite ^/out-([0-9]+)-([0-9]+).html$  
/out.php?listing\_id=$1&banner\_id=$2 break;  
}

location /directory/ {  
if (!-e $request\_filename){  
rewrite ^/([^/]+).html$ /listing.php?id=$1 break;  
}  
rewrite ^/([^/]+)/images.html$ /listing\_images.php?id=$1 break;  
rewrite ^/([^/]+)/send-message.html$ /listing\_email.php?id=$1 break;  
rewrite ^/([^/]+)/send-message-friend.html$  
/listing\_email\_friend.php?id=$1 break;  
rewrite ^/([^/]+)/reviews.html$ /listing\_reviews.php?id=$1 break;  
rewrite ^/([^/]+)/add-review.html$ /listing\_reviews\_add.php?id=$1  
break;  
rewrite ^/([^/]+)/classifieds.html$ /listing\_classifieds.php?id=$1  
break;  
rewrite ^/([^/]+)/documents.html$ /listing\_documents.php?id=$1  
break;  
rewrite ^/([^/]+)/suggestion.html$ /listing\_suggestion.php?id=$1  
break;  
rewrite ^/([^/]+)/claim.html$ /listing\_claim.php?id=$1 break;  
if (!-e $request\_filename){  
rewrite ^(.\*)$ /404.php?id=$1 break;  
}  
}

location /directory/classified {  
rewrite ^/classified/[^/]±([0-9]+).html$ /classified.php?id=$1  
break;  
rewrite ^/classified/[^/]±([0-9]+)/images.html$  
/classified\_images.php?id=$1 break;  
}

location = /sitemap.xml {  
rewrite ^(.\*)$ /xml.php?type=sitemap break;  
}

location ~ .(htaccess|tpl)$ {  
deny all;  
}

location ~/files/.(php|php3|php4|phtml|pl|cgi)$ {  
deny all;  
}

location ~ .csv$ {  
deny all;  
}

But this dosn’t seem to work, and as I’m new to using nginx I can’t get  
my head around it. Can anyone help

Posted at Nginx Forum:

> **[Converting Rewrite rules](https://forum.nginx.org/read.php?2,228027,228027#msg-228027)**
>
> I'm needing help on converting a htaccess rules to the nginx format. I've got the software installed in a sub folder called directory. In the root of that folder there is this .htaccess information: #Options +FollowSymLinks #Options -MultiViews #Op

---

<div class="post-metadata">

**Author:** ![akia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a9a28c/32.png) [@akia](https://www.ruby-forum.com/u/akia)\
**Post date:** [June 28, 2012, 9:48am UTC](https://www.ruby-forum.com/t/converting-rewrite-rules/221030/2 "2012-06-28T09:48:00Z")

</div>

Try to diff with the results of the converter:  
[http://winginx.com/htaccess](http://winginx.com/htaccess)

Posted at Nginx Forum:

> **[Re: Converting Rewrite rules](https://forum.nginx.org/read.php?2,228027,228041#msg-228041)**
>
> I'm needing help on converting a htaccess rules to the nginx format. I've got the software installed in a sub folder called directory. In the root of that folder there is this .htaccess information: #Options +FollowSymLinks #Options -MultiViews #Op

---

<div class="post-metadata">

**Author:** ![akia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a9a28c/32.png) [@akia](https://www.ruby-forum.com/u/akia)\
**Post date:** [June 29, 2012, 10:11pm UTC](https://www.ruby-forum.com/t/converting-rewrite-rules/221030/3 "2012-06-29T22:11:40Z")

</div>

Yea thats what I used to get the current rewrite rules in the first  
place but they are not working.

Posted at Nginx Forum:

> **[Re: Converting Rewrite rules](https://forum.nginx.org/read.php?2,228027,228115#msg-228115)**
>
> I'm needing help on converting a htaccess rules to the nginx format. I've got the software installed in a sub folder called directory. In the root of that folder there is this .htaccess information: #Options +FollowSymLinks #Options -MultiViews #Op
