Rewrite all directory URLs with certain exceptions

Hello

I have urls like example.com/123
I need them rewritten to example.com/?v=123

However, I want to skip certain directories from rewrite
eg.
example.com/status
example.com/admin

right now I have this:

if (!-e $request_filename){
rewrite ^/([A-Za-z0-9-]+)/?$
http://www.example.com/v.php?dl=$1redirect;
}

Problem is that all urls are rewritten… how do I put some exceptions?

Thanks for any suggestion

On Wed, Nov 28, 2012 at 3:04 PM, Cristian R. [email protected] wrote:

right now I have this:

if (!-e $request_filename){
rewrite ^/([A-Za-z0-9-]+)/?$ http://www.example.com/v.php?dl=$1
redirect;
}

Problem is that all urls are rewritten… how do I put some exceptions?

put the rewrite in a location block (e.g. inside location / { }).

Hello!

On Wed, Nov 28, 2012 at 10:04:58AM +0200, Cristian R. wrote:

right now I have this:

if (!-e $request_filename){
rewrite ^/([A-Za-z0-9-]+)/?$ http://www.example.com/v.php?dl=$1redirect;
}

Problem is that all urls are rewritten… how do I put some exceptions?

I would recommend using location matching to differentiate URIs
which should be handled differently. E.g.

location / {
    # you may want to use try_files here instead
    if (...) {
        rewrite ...
    }
    ...
}

location /status {
    ...
}

location /admin {
    ...
}

See http://nginx.org/r/location for more information.


Maxim D.
http://nginx.com/support.html

On Wed, Nov 28, 2012 at 7:11 PM, Cristian R. [email protected] wrote:

Please help, server is down :frowning:

http://nginx.org/en/docs/http/ngx_http_core_module.html#variables

Maybe something like this.

location = / {
if ($arg_v) {
rewrite ^ /v.php?dl=$arg_v;
}
}

Excellent, it worked

I have another urgent matter on a server live we just switched to

I need that links like this:
http://www.example.com/?v=JYH253CT

to be rewritten as http://www.example.com/v.php?dl=JYH253CT

Please help, server is down :frowning:


Cristian R.
Web Developement & Electronic Publishing

======
Crilance.com
Crilance.blogspot.com

On Wed, Nov 28, 2012 at 2:25 PM, Edho A. [email protected] wrote:

}
}

I tried this from a htaccess to nginx converter

if ($query_string ~ “^v=(.*)$”){
rewrite ^/index.php$ /v.php?dl=$1 break;
}

But the resulting url is /v.php?dl=%1&v=FER34S

beats me!!

to be rewritten as http://www.example.com/v.php?dl=JYH253CT
if ($arg_v) {
rewrite ^ /v.php?dl=$arg_v;
}
}

I tried this from a htaccess to nginx converter

if ($query_string ~ “^v=(.*)$”){
rewrite ^/index.php$ /v.php?dl=$1 break;
}

Try:

if ($arg_v) {
rewrite ^ /v.php?dl=$arg_v break;
}

–appa

Yes, this worked, I was also trying to get an idea of that matching in
my
attempt…

Why is $1 not matching right?


Cristian R.
Web Developement & Electronic Publishing

======
Crilance.com
Crilance.blogspot.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs