Htaccess to nginx rewrite


#1

I’ve desperately tried to convert my htaccess to nginx but sadly I just
couldn’t figure out how to do it. I really need help badly, I’m willing
to pay someone 15 dollars to just make my site work again on nginx if
someone can help me with that.


#2

On Tue, Jan 20, 2009 at 08:25:06PM +0100, Vahid Mirjamali wrote:

I’ve desperately tried to convert my htaccess to nginx but sadly I just
couldn’t figure out how to do it. I really need help badly, I’m willing
to pay someone 15 dollars to just make my site work again on nginx if
someone can help me with that.

Attachments:
http://www.ruby-forum.com/attachment/3186/htaccess.zip

Here is sample how to convert first several rules:

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

RewriteRule
^game-browser-([^/])-([^/])-([0-9])-([^/])-([^/])-([^/]).html
index.php?page=BrowseGames&start=$1&cat=$2&nav=$3&genre=$4&esrb=$5&publisher=$6
[L,NS]
RewriteRule ^image_upload.html index.php?page=Mediaupload [L,NS]
RewriteRule ^image_upload-go.html index.php?page=Mediaupload&action=go
[L,NS]
RewriteRule ^image_upload-go-ADD.html
index.php?page=Mediaupload&action=go&task=
upload [L,NS]

server {
    listen  80;
    server_name  www.pspcrazy.com;

    location ~ \.php$ {
         ...
    }

    # RewriteRule 

^game-browser-([^/])-([^/])-([0-9])-([^/])-([^/])-([^/]).html
index.php?page=BrowseGames&start=$1&cat=$2&nav=$3&genre=$4&esrb=$5&publisher=$6
[L,NS]

    location /game-browser- {
        rewrite 

^/game-browser-([^/])-([^/])-([0-9])-([^/])-([^/])-([^/]).html
/index.php?page=BrowseGames&start=$1&cat=$2&nav=$3&genre=$4&esrb=$5&publisher=$6?
last;
}

    # RewriteRule ^image_upload.html index.php?page=Mediaupload 

[L,NS]

    location = /image_upload.html {
        rewrite  ^   /index.php?page=Mediaupload   last;
    }

    ...
}

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

server {
    listen  80   default;
    server_name  _;

    rewrite  ^  http://www.pspcrazy.com$request_uri  permnent;
}

Other rules should converted as these first ones.


#3

Note:

Should be ‘permanent’ not ‘permnent’ or you will probably get an error.

Jim


#4

Hello!

On Wed, Jan 21, 2009 at 09:57:19AM +0300, Igor S. wrote:

Here is sample how to convert first several rules:

[…]

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

server {
    listen  80   default;
    server_name  _;

    rewrite  ^  http://www.pspcrazy.com$request_uri  permnent;
  •     rewrite  ^  http://www.pspcrazy.com$request_uri  permnent;
    
  •     rewrite  ^  http://www.pspcrazy.com$request_uri?  permanent;
    

(added ‘?’ to avoid query string duplication, typo fixed)

Maxim D.


#5

Igor S. wrote:

I’ve attached a new version of this, any mistakes that you notice off
the bat, as i’d like to make sure it’s ok before going live with it. If
not let me know what’s still wrong and some more examples.


#6

On Thu, Jan 22, 2009 at 08:11:01AM +0100, Vahid Mirjamali wrote:

Igor S. wrote:

I’ve attached a new version of this, any mistakes that you notice off
the bat, as i’d like to make sure it’s ok before going live with it. If
not let me know what’s still wrong and some more examples.

Attachments:
http://www.ruby-forum.com/attachment/3193/newrewrite.txt

  1. You do not need this at all:

RewriteEngine On

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

  1. In this type of rewrites with $1, $2, etc:

location = /vote-([0-9]*).html {
rewrite ^ /index.php?page=Vote&id=$1 last;
}

  •       rewrite  ^   /index.php?page=Vote&id=$1  last;
    
  •       rewrite  ^/vote-([0-9]*).html   /index.php?page=Vote&id=$1 
    

last;

  1. In this type of rewrites:

location = /polls.html {
rewrite ^ index.php?page=Polls last;
}

  •       rewrite  ^   index.php?page=Polls last;
    
  •       rewrite  ^   /index.php?page=Polls last;
    
  1. You need to place these rules inside one server and then add
    rewrite for www.pspcrazy.com:

server {
server_name www.pspcrazy.com;

location /game-browser- {
    ...
}

...

location = /rss-articles.xml {
     rewrite  ^ rss-articles.php last;
}

# do not forget about PHP handler:
location ~ \.php$ {
     ...
}

}

server {
listen 80 default;
server_name _;

 rewrite  ^  http://www.pspcrazy.com$request_uri?  permanent;

}


#7

I did all the changed but it still failed to make it work, reattached
the new htaccess converts.

Any Ideas?


#8

On Thu, Jan 22, 2009 at 10:33:08AM +0300, Igor S. wrote:

  1. You do not need this at all:

RewriteEngine On

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

  1. In this type of rewrites with $1, $2, etc:

location = /vote-([0-9]*).html {

Yet more, any regex:

  • location = /vote-([0-9]*).html {
  • location ~ /vote-([0-9]*).html {

“=” means exact match.


#9

Vahid Mirjamali wrote:

I did all the changed but it still failed to make it work, reattached
the new htaccess converts.

Any Ideas?

And attached here is the full config for just that domain.


#10

On Tue, Jan 27, 2009 at 10:12:21PM +0100, Vahid Mirjamali wrote:

I did all the changed but it still failed to make it work, reattached
the new htaccess converts.

Any Ideas?

Attachments:
http://www.ruby-forum.com/attachment/3213/newrewrite.txt

It seems you did not read the previous email:


  1. In this type of rewrites:

location = /polls.html {
rewrite ^ index.php?page=Polls last;
}

  •       rewrite  ^   index.php?page=Polls last;
    
  •       rewrite  ^   /index.php?page=Polls last;

#11

On Tue, Jan 27, 2009 at 10:12:45PM +0100, Vahid Mirjamali wrote:

Vahid Mirjamali wrote:

I did all the changed but it still failed to make it work, reattached
the new htaccess converts.

Any Ideas?

And attached here is the full config for just that domain.

Attachments:
http://www.ruby-forum.com/attachment/3214/fulthing.txt

Looking at the configuration, I’m starting to understand Python’s
author,
when he had decided to force indention.

This


server
{
listen 192.168.93.208:80;
server_name pspcrazy.com www.pspcrazy.com;

if ($host != ‘www.pspcrazy.com’ ) {
rewrite ^/(.*)$ http://www.pspcrazy.com/$1 permanent;
rewrite ^ http://www.pspcrazy.com$request_uri? permanent;
}

should be rewritten as two servers (as I have already told):


server {
listen 192.168.93.208:80;
server_name pspcrazy.com;

rewrite  ^  http://www.pspcrazy.com$request_uri?  permanent;

}

server {
listen 192.168.93.208:80;
server_name .com www.pspcrazy.com;

...

This


location ~* ^/forums/((admincp/images|clientscript|cpstyles|images)/.*)$
{
root /home/user/pspcrazy.com/httpdocs;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php last;
}

}

should be rewritten as:


location ~* ^/forums/((admincp/images|clientscript|cpstyles|images)/.*)$
{
root /home/user/pspcrazy.com/httpdocs;
expires 30d;

error_page  404  = @php;

}

location @php {
root /home/user/pspcrazy.com/httpdocs;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_TRANSLATED $document_root/index.php;
}


etc. Do not use "if"s at all.