Forum: NGINX htaccess to nginx rewrite

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e6a19cfb5ea4ca1cf42f1db65550c35?d=identicon&s=25 Helgem Megelaat (vmirjamali)
on 2009-01-20 20:25
Attachment: htaccess.zip (2 KB)
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.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-21 08:08
(Received via mailing list)
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.
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-01-21 13:42
(Received via mailing list)
Hello!

On Wed, Jan 21, 2009 at 09:57:19AM +0300, Igor Sysoev 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 Dounin
2c6f80fff253635f12c249ef4f116796?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-01-21 14:27
(Received via mailing list)
Note:

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

Jim
8e6a19cfb5ea4ca1cf42f1db65550c35?d=identicon&s=25 Helgem Megelaat (vmirjamali)
on 2009-01-22 08:11
Attachment: newrewrite.txt (20 KB)
Igor Sysoev 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.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-22 08:46
(Received via mailing list)
On Thu, Jan 22, 2009 at 08:11:01AM +0100, Vahid Mirjamali wrote:

> Igor Sysoev 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]

2) 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;


3) 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;

4) 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;
}
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-22 08:51
(Received via mailing list)
On Thu, Jan 22, 2009 at 10:33:08AM +0300, Igor Sysoev 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]
>
> 2) 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.
8e6a19cfb5ea4ca1cf42f1db65550c35?d=identicon&s=25 Helgem Megelaat (vmirjamali)
on 2009-01-27 22:12
Attachment: newrewrite.txt (20 KB)
I did all the changed but it still failed to make it work, reattached
the new htaccess converts.

Any Ideas?
8e6a19cfb5ea4ca1cf42f1db65550c35?d=identicon&s=25 Helgem Megelaat (vmirjamali)
on 2009-01-27 22:12
Attachment: fulthing.txt (3 KB)
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.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-28 11:30
(Received via mailing list)
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:

--------------
3) 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;
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-28 11:41
(Received via mailing list)
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.
This topic is locked and can not be replied to.