NGINX rewrite rules and directory conflict
December 23, 2010 05:51PM
Hello, i have some problems with rewrite in nginx:
i`ll try explain the problem:
my site have rewrite rules like this:
http://domain/index.php?p=page1
http://domain/index.php?p=page2
etc.
after rewrite:
[code]
rewrite ^/([a-zA-Z_0-9\-]+)/?$ /index.php?p=$1 last;
[/code]
http://domain/page1/
http://domain/page2/
etc.
Every thing works fine until now when i make a forum in http://domain/forum/
when i browse to http://domian/forum/index.php it's work

but when i browse http://domain/forum/
not work.
and also i do not need rewrite rules in forum directory
here is my all rewrite rules:
[code]
rewrite ^/?$ /index.php last;
rewrite ^/forum/([a-z]=.*) /forum/index.php?$1 last;
rewrite ^/news,1,([0-9]+).htm?$ /index.php?p=news&area=1&id=$1 last;
rewrite ^/newsarchiv,([0-9]+),1.htm?$ /index.php?p=category&area=1&catid=$1 last;
rewrite ^/newsfrom/([0-9]+)?$ /index.php?p=category&area=1&catid=$1 last;
rewrite ^/newsfrom/([0-9]+)/?$ /index.php?p=category&area=1&catid=$1 last;
rewrite ^/newsfor/([0-9]+)/?$ /index.php?p=category&area=1&date=$1 last;
rewrite ^/newsfor/([0-9]+)?$ /index.php?p=category&area=1&date=$1 last;
rewrite ^/news/([0-9]+)?$ /index.php?p=news&area=1&id=$1 last;
rewrite ^/news/([0-9]+)/?$ /index.php?p=news&area=1&id=$1 last;
rewrite ^/category/([0-9]+)/page([0-9]+)?$ /index.php?p=category&area=1&catid=$1&page=$2 last;
rewrite ^/category/date([0-9]+)/page([0-9]+)?$ /index.php?p=category&area=1&date=$1&page=$2 last;
rewrite ^/([a-zA-Z_0-9\-]+)/?$ /index.php?p=$1 last;
rewrite ^/([a-zA-Z_0-9\-]+)?$ /index.php?p=$1 last;
rewrite ^/static-([a-zA-Z_0-9\-]+)-1.html?$ /index.php?p=$1 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([0-9\-]+)/page([0-9]+)?$ /index.php?p=$1&id=$2&page=$3 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([0-9\-]+)/page([0-9]+)/?$ /index.php?p=$1&id=$2&page=$3 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([0-9]+)?$ /index.php?p=$1&id=$2 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([0-9]+)/?$ /index.php?p=$1&id=$2 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([a-zA-Z_0-9\-]+)?$ /index.php?p=$1&id=$2 last;
rewrite ^/([a-zA-Z_0-9\-]+)/([a-zA-Z_0-9\-]+)/?$ /index.php?p=$1&id=$2 last;
rewrite ^/rss/?rss=news&toid=([0-9]+)?$ /rss/index.php?rss=news&toid=$1 last;
rewrite ^/rss/?$ /rss/index.php last;
rewrite ^/rss/news/([0-9]+)/1.htm?$ /rss/index.php?rss=news&toid=$1 last;
rewrite ^/rss/news/([a-zA-Z_0-9\-]+)/([0-9]+)/1.htm?$ /rss/index.php?rss=news&categ=$1&toid=$2 last;
if ( !-e $request_filename ) {
rewrite ^ /index.php permanent;
}
[/code]

i just want create directory forum and i want install a forum in it.
Please i really need some expert advice. Thank you.
Re: NGINX rewrite rules and directory conflict
January 09, 2011 11:09PM
That top rule looks a little off. For this location block, do you have "index index.php" in the configuration? That should cover both "/" and "/forum" URLs, and will serve index.php in those cases.

Also, if the forum doesn't need these sorts of rules, you can actually define a "location /forum" block and simply specify its rules there. Otherwise, keep in mind that you'll always have to specify forum rules with "^/forum/" - the "^" means it's the start of the URL.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 99
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready