Welcome! Log In Create A New Profile

Advanced

Apache to nginx rewties giving 404

Posted by Hiiragi 
Apache to nginx rewties giving 404
October 12, 2009 01:01AM
I'm in the process of moving from Apache to nginx but have had to put that on hold because one site I host has rules that I can't make work under nginx. The urls seem to be rewritten correctly, however they always 404.

Here are the rules as they appear in httpd.conf
[code]
RewriteRule ^index.(php|html)$ news.php [QSA]
RewriteRule ^logout.(html)$ user/login.php?do=logout [QSA]
RewriteRule ^news.html$ news.php [QSA]
RewriteRule ^news/(.*),(.*).html$ news.php?id=$1&page=$2 [QSA]
RewriteRule ^news/(.*).html$ news.php?id=$1 [QSA]
RewriteRule ^rss/(.*).(xml|rss)$ rss.php?do=$1 [QSA]

RewriteRule ^gallery/category/(.*)$ gallery.php?d=$1 [QSA]
RewriteRule ^gallery$ gallery.php?d=$1 [QSA]

RewriteRule ^gallery/(.*).html$ gallery.php?d=$1 [QSA]
RewriteRule ^gallery.php/category/(.*)$ gallery.php?d=$1 [QSA]

RewriteRule ^manga/(.*).html$ manga.php?path=$1 [QSA]
RewriteRule ^download/(.*).html$ file.php?path=$1 [QSA]
RewriteRule ^view_profile/(.*).html$ user/view_profile.php?user=$1 [QSA]
RewriteRule ^(.*),(.*),(.*).html$ $1.php?do=$2&id=$3 [QSA]
RewriteRule ^(.*),(.*).html$ $1.php?do=$2 [QSA]
RewriteRule ^(.*).html$ $1.php [QSA]
[/code]

and this is what I've been trying in nginx.conf

[code]
location / {
root /home/site;
index news.php;

rewrite ^index.(php|html)$ news.php last;
rewrite ^logout.(html)$ user/login.php?do=logout last;
rewrite ^news.html$ news.php last;
rewrite ^news/(.*),(.*).html$ news.php?id=$1&page=$2 last;
rewrite ^news/(.*).html$ news.php?id=$1 last;
rewrite ^rss/(.*).(xml|rss)$ rss.php?do=$1 last;

rewrite ^gallery/category/(.*)$ gallery.php?d=$1 last;

rewrite ^gallery/(.*).html$ gallery.php?d=$1 last;
rewrite ^gallery.php/category/(.*)$ gallery.php?d=$1 last;

rewrite ^manga/(.*).html$ manga.php?path=$1 last;
rewrite ^download/(.*).html$ file.php?path=$1 last;
rewrite ^view_profile/(.*).html$ user/view_profile.php?user=$1 last;
rewrite ^(.*),(.*),(.*).html$ $1.php?do=$2&id=$3 last;
rewrite ^(.*),(.*).html$ $1.php?do=$2 last;
rewrite ^(.*).html$ $1.php last;
}
[/code]

I was given the httpd.conf rewrites from their coder, but he didn't know how to use nginx so it was up to me to try and convert it over. They're basically all the same except for the addition of last at the end of each rule. As I understand it, nginx does QSA by default.

Is there anything I'm missing?
Re: Apache to nginx rewties giving 404
October 12, 2009 10:21AM
Hiiragi Wrote:
-------------------------------------------------------

> Is there anything I'm missing?

Yes, some forward slashes. Try:


[code]
location / {
root /home/site;
index news.php;

rewrite ^/index.(php|html)$ /news.php last;
rewrite ^/logout.(html)$ /user/login.php?do=logout last;
rewrite ^/news.html$ /news.php last;
rewrite ^/news/(.*),(.*).html$ /news.php?id=$1&page=$2 last;
rewrite ^/news/(.*).html$ /news.php?id=$1 last;
rewrite ^/rss/(.*).(xml|rss)$ /rss.php?do=$1 last;

rewrite ^/gallery/category/(.*)$ /gallery.php?d=$1 last;

rewrite ^/gallery/(.*).html$ /gallery.php?d=$1 last;
rewrite ^/gallery.php/category/(.*)$ /gallery.php?d=$1 last;

rewrite ^/manga/(.*).html$ /manga.php?path=$1 last;
rewrite ^/download/(.*).html$ /file.php?path=$1 last;
rewrite ^/view_profile/(.*).html$ /user/view_profile.php?user=$1 last;
rewrite ^/(.*),(.*),(.*).html$ /$1.php?do=$2&id=$3 last;
rewrite ^/(.*),(.*).html$/$1.php?do=$2 last;
rewrite ^/(.*).html$ /$1.php last;
}
[/code]

--
Jim Ohlstein
Re: Apache to nginx rewties giving 404
October 12, 2009 10:48AM
Wow, thanks!

One more question, though.

Some URLs that get rewritten have a + where a space should be and apparently nginx doesn't like there whereas Apache didn't mind. Is there a way to a) remove them or b) make them understood?
Re: Apache to nginx rewties giving 404
October 12, 2009 08:43PM
That's going to be difficult. I don't believe nginx understands spaces in URI's. Recoding the app might be best.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 251
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