I'm having a difficult time figuring out how should I make a hole bunch of redirects (301) to Nginx. Maybe you can give me some help.
Basically I have a few hundred of url's like this one above:
http://www.website.com/product/intl/bg-BG/browserchoice/download.html?track=1871
And I need to redirect to:
http://www.website.com/home/download/download.php?prod=browser&track=1871
How should I do it? (*bg-BG from source is the single variable that changes)
Please help me.
Thanks.
Please try this, it peforms internal redirect in nginx:
rewrite ^/product/intl/.*/browserchoice/download.html$ /home/download/download.php?prod=browser&$args break;
But if you really want redirect (this is not a good choice) :
rewrite ^/product/intl/.*/browserchoice/download.html$ http://www.website.com/home/download/download.php?prod=browser&$args permanent;
I also suggest you to read official documentation here http://wiki.nginx.org/HttpRewriteModule
Related
I have rewritten all external links sent to standard output on the fly as an internal link in PHP from https://externalsite.com to https://myexamplesite.com/https://externalsite.com, yet I want Nginx to handle the request for this URL and not PHP.
I have tried it via the line below, but it is not working
rewrite ^/http(.+)$ http$1 redirect;
Please advise on the best way to redirect https://myexamplesite.com/https://externalsite.com, to https://externalsite.com on request
I was able to have it work with this.
rewrite ^/https?\W+(.*) https://$1 redirect;
I am not sure why the former did not work but seems NGINX is passing it back internally.
NGINX seems not to honor an external redirect without the "https://" statically written before and jointly with the second option of the directive despite being captured in the parenthesis.
I've a problem I tried to fix but I need help. I'm going to try to explain you what I need to do:
I have a nginx web server and I need to add a location to redirect my main page example.com to web.example.com but just this page. For anothers pages I need to use example.com/path.
For example any request to example.com it needs to redirecto to web.example.com (I can do that).
My problem start when I have a request to example.com/path and my location redirect to web.example.com/path that is not what I need.
I tried with some regular expresion but it does't work, any ideas?
Thank you!
If you only need a redirect for the main page try exact match location
location = / {
return 302 https://...$args;
}
I'm basically trying to have nginx redirect:
https://website1.com/program_video/programXXX.mp4
to
http://website2.com/ProgramsVideos/programXXX.mp4
Given that "XXX" is the id of the video and might change.
I've been wandering around stackoverflow and nginx directory but wasn't able to get anything to work.
Last thing I tried was:
rewrite "https://website1.com/program_video/([a-zA-Z0-9]{23})\.mp4)$" http://website2.com/ProgramsVideos/$1 permanent;
But it doesn't redirect anything...
Any help would be much appreciated.
I am totally newbie on NGINX reverse proxy solution and its seems to getting hard to understand all the terminology. I am looking for a solution as follows. I would really appreciate anybody's help to configure the same.
We have an internal web server which we would like to publish at WWW site but don't want customer to see internal server URL. As example:
Customer access www.mycompany.com/track --> NGINX read the track and then redirect URL to internal server.com.au/tracker . We dont want customer to see this address.
Any suggestion?
Cheers,
Sandy
It is much better in this case to use the proxy. Rewrites are meant for URLs within the same domain or to redirect the client (which would show in the url).
Try this:
location / {
proxy_pass http://internal.example.com/;
proxy_set_header Host $host;
}
Rewriting on nginx is quite the same than on Apache :) The syntax varies.
When Apache uses RewriteRule, nginx uses rewrite. May I suggest you this reference http://wiki.nginx.org/HttpRewriteModule ? Check 2.4 and 2.5 for rewriting-specific documentation. You'll find information about the rewrite syntax, and rewriting options.
There is a quick example from above, if you just need the basic syntax :
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
By the way, if you want to work from examples, you can transform your Apache .htaccess file into a piece of nginx configuration, using this tool : http://winginx.com/htaccess
I suspect this will be quite simple, yet I can't seem to get my head around the nginx rewrite system. Hopefully someone could chime in and help me out?
Quite simply, I need..
http://example.com/?c=foo
to to be rewritten to...
http://foo.example.com
Thank-you in advance if you've taken pitty on this nginx noob :)
I'll keep having a go at this, and in the unlikely event I hit a 'eureka' moment, I'll update this to help anyone who's having/will ever have this similar 'problem'.
Cheers.
Actually, it is impossible to make internal redirect to other domain in Nginx. But there are two available solutions:
1) Simple: make redirect to specified address. Example:
if ( $arg_c ) {
rewrite ^ http://$arg_c.example.com;
}
2) Complex: if you use Nginx as a proxy between php-fpm, apache or something else, you could set the Host header in this way::
set $new_host example.com;
if ( $arg_c) {
set $new_host $arg_c.example.com;
}
and pass it as a parameter:
proxy_set_header Host $new_host;