#1  
Old 6th June 2012, 22:12
akia akia is offline
HowtoForge Supporter
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default NGINX Rewrites

Hi All,

Can someone help me in rewriting the .htaccess rules for php my directory to the nginx format.


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

# This can be uncommented to compress js and css files
#<IfModule mod_deflate.c>
#<FilesMatch "\.(js|css)$">
# SetOutputFilter DEFLATE
#</FilesMatch>
#</IfModule>

# 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>

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

<IfModule mod_rewrite.c>
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]

</IfModule>
Reply With Quote
Sponsored Links
  #2  
Old 6th June 2012, 23:28
akia akia is offline
HowtoForge Supporter
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've found a converter thats come up with this. but I don't know whether its right or not

# nginx configuration

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

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

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

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

location /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 /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 / {
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 /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;
}
Reply With Quote
  #3  
Old 7th June 2012, 23:08
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,740 Times in 2,575 Posts
 
Default

After taking a short glance, I'd say this looks good.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
nginx Segmentation fault Error,The Perfect Server - CentOS 6 With nginx [ISPConfig 3] alihan1988 HOWTO-Related Questions 0 2nd February 2012 17:07
Nginx doesnt restart after installation of ISPConfig 3 cyprus Installation/Configuration 2 6th November 2011 18:48
A Working Nginx Catchall with ISPConfig 3. renders Tips/Tricks/Mods 4 15th April 2011 21:53
Nginx and PHP and Fastcgi Paladinemishakal Installation/Configuration 1 4th January 2011 13:45
Nginx on Fedora 11 Nammut HOWTO-Related Questions 1 3rd October 2009 16:35


All times are GMT +2. The time now is 13:03.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.