How do I rewrite URIs of the form
http://domain1/one/two?three=four
to
http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour
using nginx?
rewrite ^(.*)$ http://domain2?path=$scheme://$host$1 last;
OR
rewrite ^(.*)$ http://domain2?path=$scheme://$host$reques_uri last;
More on nginx variables.
Related
I want to send a vhost's requests to git.domain1.tld to sub.domain2.tld/git
I suppose that would conflict with overwritten files so how can I get that domain to point to that location?
You can try this:
location / {
proxy_pass https://sub.domain2.tld/git;
}
Or
rewrite ^/$ https://sub.domain2.tld/git permanent;
rewrite ^/(.*)$ https://sub.domain2.tld/git/$1 permanent;
If I have the following URL:
https://kl-office.com/directory
How can I configure Nginx to rewrite the above URL as:
https://kl-office.com
You could try this:
rewrite ^.*$ / permanent;
Although, this will rewrite any request to /
I'm very new to this WordPress/Nginx/Rewrites things and trying get my head round it. So asking the question straight: What's the difference between these two rewrites?
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-/]+(/wp-admin.*) $1 last;
rewrite ^/[_0-9a-zA-Z-/]+(/wp-include.*) $1 last;
rewrite ^/[_0-9a-zA-Z-/]+(/.*\.php)$ $1 last;
}
and
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
The former doesn't work for the sites with virtual directory setup but the latter does. How do they different? Something to do with WordPress virtual-directory itself? Sorry if this has been asked before but I cannot figure out anything.
Best,
San
After sifting through the files and directories beginning with wp-, the /wp-content directory is the only difference on my WordPress installation.
So the answer is probably that:
rewrite ^/[_0-9a-zA-Z-/]+(/wp-content.*) $1 last;
is missing from the first set of rules.
How do you do nginx rewrite rule to convert
example.com/?subtopic=forum&action=show_board&id=1
into this
example.com/forum/board/1
or this
example.com/?subtopic=characters&name=Eternal
into this
example.com/characters/Eternal
I've found and tried to play around with this code
location / {
rewrite ^/subtopic/(.*)$ /?subtopic=$1 last;
}
but it doesnt work (i'm really a newbie into rewriting)
You may try these rules:
rewrite /(.*)/(.*)/(\d+) /?subtopic=$1&action=show_$2&id=$3 last;
rewrite /(.*)/(.*) /?subtopic=$1&name=$2 last;
I'm configuring nginx with multiple server names, and trying to set up the following rewrite rules
redirect / on old.domain.com to new.domain.com/specific_page.php
redirect old.domain.com/$1 to new.domain.com/$1
In my "server" configuration, I have already the first rewrite condition working, but I cannot find the way to write the second.
if ($host = 'old.domain.com' ) {
rewrite ^/ http://new.domain.com/my-specific/link/list/info.php permanent;
rewrite ^/(.*)$ http://old.domain.com/$request_uri? permanent;
}
Any ideas how to handle easily this scenario? (I realise this might be an unusual setup.)
Actually I managed to solve my problem :
if ($host = 'old.domain.com' ) {
rewrite ^/$ http://new.domain.com/my-specific/link/list/info permanent;
rewrite ^(.*)$ http://old.domain.com$request_uri? permanent;
}
the first rewrite rule ^/$ matches only http://old.domain.com/ and rewrites it to the requested URL
The second rewrite rule ^(.*)$ matches whatever is behind the http://old.domain.com/ and rewrites the domain only.