2011年2月1日星期二

Re: RewriteCond command

On 2 Fev 2011 04h12 WET, nginx-forum@nginx.us wrote:

> thanks Antonio
>
> if i could find to change & to ? i am going to solve my problem
>
>
> incorrect
> http://www.mysite.com/search/web&search=katy%20perry&type=web
>
> correct
> http://www.mysite.com/search/web?search=katy%20perry&type=web
>

Try this:

location /search/web {
rewrite ^ /search/web?$args?;
}

>
> what should i add into my conf
> server {
> listen 81;
> server_name *.mysite.ws;
> access_log /var/log/mysite.access.log main;
> error_log /var/log/mysite.error.log;
> root /home/mysite/www;
> index index.php index.html;
>
> rewrite /(.*)(style\.css)$ /$2 last;
> rewrite /(.*)(lightbox\.css)$ /$2 last;
> rewrite /(.*)(userdata\/)(.*)$ /$2$3 last;
> rewrite /(.*)(maps\/)(.*)$ /$2$3 last;
> rewrite /(.*)(test\/)(.*)$ /$2$3 last;
> rewrite ^/(.*)(index\.php)(\/?)(.*)$ /index.php?page=index/$4 last;
> rewrite /(.*)(install\/)(.*)$ /$2$3 last;
> rewrite /(.*)(addon\/)(.*)$ /$2$3 last;
> rewrite /(.*)(cron\/)(.*)$ /$2$3 last;
> rewrite /(.*)(js\/)(.*)(\.js)$ /$2$3$4 last;
> rewrite /(.*)(images\/)(.*)(\.)(gif|jpe?g|png|ico)$ /$2$3$4$5 last;
> rewrite ^/(.*)$ /index.php?page=$1 last;

There's room for improvement above. You have rules that are repeated,
it just changes the second pattern. E.g.,

> rewrite /(.*)(maps\/)(.*)$ /$2$3 last;
> rewrite /(.*)(test\/)(.*)$ /$2$3 last;
> rewrite /(.*)(install\/)(.*)$ /$2$3 last;
> rewrite /(.*)(addon\/)(.*)$ /$2$3 last;
> rewrite /(.*)(cron\/)(.*)$ /$2$3 last;

Can be placed in a single rule:

rewrite /(.*)((maps|test|install|addon|cron)\/)(.*)$ /$2$3 last;

> location / {
> try_files $uri $uri/ /index.php?q=$request_uri;
> }
>
> location ~ \.php$ {
> root html;
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME /home/mysite/www$fastcgi_script_name;
> include fastcgi_params;
> }
> }
>
> i couldnt convert this into my conf
>
> RewriteCond %{request_uri} !^index\.php

This is just the condition, what's the rule?

if ($request_uri != index.php) {
(...)
}

Note that an if is in fact an implicit location, so the only safe
thing to do inside is to return a status code or a rewrite with the
'last' flag. Cf. http://wiki.nginx.org/IfIsEvil

--- appa


_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx

没有评论:

发表评论