I have this redirect script in my nginx.conf file. I want to redirect to http:// site but my origin is https:// how do I remove the 's' from the url? Adding the http:// to the pass won't work
rewrite ^(?!/mt/)(.*)$ /content$1 break;
Origin: https://blog.com/mt/content/apple/site.php
Redirect: http://blog.com/content/apple/site.php
Use protocol and host in redirect:
rewrite ^(?!/mt/)(.*)$ http://blog.com/content$1 break;
Related
When access this url: https://bar.com?type=search&keyword=foobar in PC, redirect to another url and whole source url as a request param,
https://baz.com/qrCode?from=https://bar.com?type=search&keyword=foobar
Nginx config:
if ( $http_user_agent !~* "(Android|iPhone)" ){
rewrite ^/(.*)$ https://baz.com/qrCode?from=https://bar.com$request_uri? permanent;
}
But exists this problem, that is the source url incomplete.
desired effect like below
How to implement is in Nginx?
I have several url's that I would like to rewrite in NGINX
for example:
From: app.example.com/calendar
To: calendar.example.com
Or
From: app.example.com/meetings
To: meetings.example.com
I would still like to keep the app.example.com so it's not being removed from the redirect, but just create subdomains for certain URLs.
How can I do this in NGINX conf file?
All the best.
Redirect Subdomain to Folder in NGINX
Just add the following location block in your server configuration, inside server block, above the location / block.
location ^~ /calendar {
rewrite ^/calendar/?(.*)$ https://calendar.example.com/$1 permanent;
}
In the above code replace blog.example.com with your subdomain, and /calendar with your subdirectory. The above location block will listen to all requests sent to example.com/calendar. It redirects all those requests to calendar.example.com subdomain of your website. $1 is the URL stub after subfolder in requested URL. We add permanent keyword at the end of rewrite directive to cause a permanent redirect.
So it will permanently redirect subfolder to subdomain along with URL string.
I have the following URL redirect in my Nginx server block:
location /news/ { return 301 https://example.com/blog/category/news; }
I want the above location rule to work for URLs with or without the trailing slash, eg:
OK: https://example.com/news
OK: https://example.com/news/
But not in this case:
NOT OK: https://example.com/newsletter
NOT OK: https://example.com/newsmaker
How to change my location redirect rule to reflect this requirement?
I want to proxy from main domain to subdomain like that;
example.com/blog => blog.example.com
example.com/blog/test => blog.example.com/test
I use this configuration :
location /blog/ {
proxy_pass http://blog.example.com;
}
But when I go to url example.com/blog , it redirects me to blog.example.com/blog or
example.com/blog/test ,it redirects me to blog.example.com/blog/test.
How can I remove /blog from subdomain which comes from main domain proxy?
We have nginx setup with location proxy pass and required one specific url need to redirect or rewrite when it was hit.
Src Url:
https://application-url:port/services/app1/callback/?oauth_token=<<tokens>>
Dest Url:
https://application-url:port/services/app1/callback?oauth_token=<<tokens>>
Any solution here.
It seems src and dest url are same. if you want to rewrite the url:
then add below lines in your server
location /callback {
rewrite ^/callback(.*) https://application-url:port/services/app1/callback$?oauth_token=<<tokens>> permanent
}