Welcome! Log In Create A New Profile

Advanced

Help converting Apache HTACCESS directives to nginx?

August 08, 2010 11:20PM
Hi, I'm brand new to nginx and I am trying to convert the app I wrote over from Apache as I need the ability to serve a lot of clients at once without a lot of overhead! I'm getting the hang of setting up nginx and FastCGI PHP but I can't wrap my head around nginx's rewrite format just yet. I know you have to write some simple script that goes in the server {} block in the nginx config but I'm not yet familiar with the syntax. Could anyone with experience with both Apache and nginx help me convert this to nginx format? Thanks!
[code]
Options +FollowSymLinks
RewriteEngine On

# ------------------------------------------------------ #
# Rewrite from canonical domain (remove www.) #
# and from beta subdomain (remove beta.) #
# ------------------------------------------------------ #

RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^beta.domain.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]

# ------------------------------------------------------ #
# This is for maintenance mode (if /msg.html exists) #
# ------------------------------------------------------ #

# Rewrite everything else and attempt a TwitStamp
# Not a file, directory, or file.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php !-f
RewriteCond %{DOCUMENT_ROOT}/msg.html -f
RewriteRule ^([a-z0-9_\-@#\ "'\+]+)/?([a-z0-9_\-]+)?(\.png|/)?$ generation/image.php?user=${escapemap:$1}&template=${escapemap:$2} [NC,L]

# Redirect everything to maintenance page
# Not msg.html, not image.php, not from my IP
RewriteCond %{REQUEST_URI} !/msg.html$
RewriteCond %{REQUEST_URI} !/generation/image.php$
RewriteCond %{REMOTE_HOST} !^76\.178\.84\.13
RewriteCond %{REMOTE_HOST} !^76\.19\.200\.16
RewriteCond %{DOCUMENT_ROOT}/msg.html -f
RewriteRule $ /msg.html [NC,L]

# ------------------------------------------------------ #
# This redirects index.php to / #
# ------------------------------------------------------ #

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(index|index\.php)\ HTTP/
RewriteRule ^(index|index\.php)$ http://domain.com/ [R=301,L]

# ------------------------------------------------------ #
# This rewrites 'directories' to their PHP files, #
# fixes trailing-slash issues, and redirects .php #
# to 'directory' to avoid duplicate content. #
# ------------------------------------------------------ #

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)/$ http://domain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.]+\.php\ HTTP/
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)\.php$ http://domain.com/$1 [R=301,L]

# ------------------------------------------------------ #
# If it wasn't redirected previously and is not #
# a file on the server, rewrite to a TwitStamp #
# ------------------------------------------------------ #

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-@#\ "'\+]+)/?([a-z0-9_\-]+)?(\.png|/)?$ generation/image.php?user=${escapemap:$1}&template=${escapemap:$2} [NC,L]
[/code]
Subject Author Posted

Help converting Apache HTACCESS directives to nginx?

christek August 08, 2010 11:20PM

Re: Help converting Apache HTACCESS directives to nginx?

st1905 August 22, 2010 10:55AM

Re: Help converting Apache HTACCESS directives to nginx?

Igor Sysoev August 22, 2010 02:12PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 279
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready