1

Whenever it's a bot, I'd like to append a single query parameter at the end of the URL in nginx.

So that URLs like https://videomail.io/11e4-38ba-b1a12cc0-8849-cbb56781aee9/ will become https://videomail.io/11e4-38ba-b1a12cc0-8849-cbb56781aee9/?crawl=1

Or without the slash at the end https://videomail.io/11e4-38ba-b1a12cc0-8849-cbb56781aee9 will result into https://videomail.io/11e4-38ba-b1a12cc0-8849-cbb56781aee9?crawl=1

If the parameter crawl already exist, no modification is wanted. How can I do that in nginx?

I tried with this but it didn't work

if ($crawling = 1) {
    rewrite ^(.*)$ $1?crawl=1? break;
}

Any clues?

1 Answer 1

1

I think you need to modify like this:

if ($arg_crawl = 1 ){
        rewrite ^(.*)$ $1?crawl=1 break;
}

nginx is not surport to check if exist to a parameter,if you want archive the goal,you can try the openresty,use some lua code to do it; http://wiki.nginx.org/HttpLuaModule basiclly like this: set_by_lua $crawl 'if ngx.var.crawl == nil then return 1 else return 0 end';

if ( $crawl = 1 ){
    rewrite ^(.*)$ $1?crawl=1 break;
}
if ( $crawl =0 ){
   set 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.