vBulletin Rewrite rule on Nginx - vbulletin

I have link
www.example.com/vb/?t=334158
want rewrite it to
http://www.example.com/vb/showthread.php?t=334158
used all of this
rewrite ^/vb/?t=([0-9]+) /vb/showthread.php?t=$1 permanent;
rewrite ^/vb/\?t=([0-9]+) /vb/showthread.php?t=$1 permanent;
but its not working

Related

Nginx redirect without scheme and hostname

I have used return or rewrite in Nginx to redirect, but both will redirect with the http header Location which has value of the full url, but I want it just value the path.
for example:
return 301 /test;
or
rewrite ^/$ /test permanent;
will has the Location value of
http://www.example.com/test
but I want it be just
/test
I wonder if it is possible.
Solved.
as of 1.11.8, just set the directive(Thanks to #RichardSmith):
absolute_redirect off;
before 1.11.8, I find a wonderful answer(Thanks to #xiaochen):
https://stackoverflow.com/a/39462409

Nginx redirect http to https and remove trailing slashes with one single redirect

I want to redirect http to https and remove trailing slashes in nginx with one single redirect. The solution I have today is the following:
server {
listen 80;
server_name www.example.com
rewrite ^/(.*)/$ /$1 permanent;
return 301 https://$host$request_uri;
}
The problem with this solution is that it will give two redirects
Gives Two redirects:
http://www.example.com/test/ --> http://www.example.com/test
http://www.example.com/test --> https://www.example.com/test
Is it possible to make a solution where you only get one single redirect like bellow?
http://www.example.com/test/ --> https://www.example.com/test
when I looked through the documentation of nginx rewrite and return methods I felt like it should be possible to do it with a single rewrite somehow:
rewrite ^/(.*)/$ https://$host$request_uri permanent;
But nothing I have tried have given me the correct results.
You already had the components of a correct solution. Use the scheme and hostname, together with the capture to construct the destination URL:
rewrite ^/(.*)/$ https://$host/$1 permanent;

How to do redirection in NGINX

May I ask Where and How to redirect
http://domain.com, http://www, https://domain.com
to
https://www
?
Where
In your Nginx config file (the main or vhost depending on your setup)
How
Try rewrite:
server {
listen 80;
server_name www.domain.com domain.com;
rewrite ^ https://www.doamin.com$request_uri? permanent;
}
or return:
server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://www.domain.com$request_uri
}
Choice is your when it comes to Return vs Rewrite:
REWRITE
Only the part of the original url that matches the regex is rewritten.
Slower than a Return.
Returns HTTP 302 (Moved Temporarily) in all cases, irrespective of permanent.
Suitable for temporary url changes.
RETURN
The entire url is rewritten to the url specified.
Faster response than rewrite.
Returns HTTP 301 (Moved Permanently).
Suitable for permanent changes to the url.
No need to set permanent.
Officila Nginx Docs on return/rewrite.

nginx: redirect domain1 to domain2 with the same link

How to redirect links from one domain to another and leave the same link structure?
for exampke: i would like to redirect domain.com/ma-page/15/03/ to domain.org/ma-page/15/03/
what i've tried
server_name domain.com;
#rewrite ^/(.*) http://domain.org permanent;
#rewrite ^ http://domain.org$request_uri? permanent;
rewrite ^/(.*) http://domain.org/$1 permanent;

Nginx redirect domain.com/blog/posts to sub.domain.com/blog/posts

Yet another nginx redirect question.
I've been trying to redirect domain.com/blog/post-1, /blog/post-2 to sub.domain.com/blog/post-1, etc.
Any pointers?
If you don't want to serve anything on domain.com without subdomains, add this block:
server {
server_name domain.com;
return 301 $scheme://sub.domain.com$request_uri;
}
If you want to use it somehow, add this to your domain.com server block:
location /blog {
rewrite ^ http://sub.domain.com$request_uri? permanent;
}
Of course, in any case you want sub.domain.com server block which is catching this request.