I'm try to set up the subdomains with Nginx, but I get some error. The following is my config:
server {
listen 80;
server_name dimain.com *.domain.com;
root /path/to/fuelphp_project/public;
location / {
index index.php index.html index.htm;
if ($host ~ (.*)\.(.*) ) {
set $sub_name $1;
rewrite ^/(.*)$ /index.php/$sub_name/$1 last;
break;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
break;
}
}
...
}
I want to the results like:
sub1.domain.com/c1/a1 -> domain.com/sub1/c1/a1
sub2.domain.com/c2/a2 -> domain.com/sub2/c2/a2
How to correct it?
server {
server_name sub1.domain.com;
return 301 "http://domain.com/sub1${uri}";
}
Would this work for you?
I just noticed an answer to this here: https://serverfault.com/questions/426673/nginx-redirect-subdomain-to-sub-directory
server {
server_name ~^(?<sub>[a-zA-Z0-9-]+)\.domain\.com$; # will cause the sub-domain to be placed in $sub
return 301 "http://domain.com/${sub}${uri}";
}
I think the regular expression also can be a very cool solution... Depends what you need.
Related
I want the Request URL to be converted from
http://host.com/newname/abc?def= to
http://newname/abc?def=
here is the config file
server {
listen 80;
server_name
host.com
location / {
rewrite ^(.+)/$ $1 permanent;
rewrite ^(.+)/index\.html$ $1 permanent;
rewrite ^(.+)\.html$ $1 permanent;
try_files /$host/public/$uri #webserver;
}
}
Adding above line worked form me
location / {
rewrite ^ $scheme://$request_uri? permanent;
}
But it replaces the url in user browser which i donn't want to happen.
Any way to achieve it
You can try this:
location /newname{
proxy_pass http://example.com/newname/abc?def=;
}
or
location /newname{
proxy_pass http://newname/abc?def=;
}
i need rewrite for domain whois for example http://domainname.ltd/example.com must be call http://domainname.ltd/whois.php?d=example.com
i try location examples but not working.
you can do it like this:
server {
listen 80;
server_name test.com;
location = /whois.php {
proxy_pass http://your_origin_host.com
}
location ~ \/(.*) {
set $domain_query $1;
set $args "d=${domain_query}";
rewrite ^ /whois.php last;
}
}
I currently have a domain https://dongyhuynhtantrieu.com and now I want to convert it to https://bacsicare.com, how do I do it? I'm currently using wordpress and nginx. I tried the code but it didn't work.
server {
server_name www.example.com;
rewrite ^ http://example.com$request_uri? permanent;
}
You can use return:
server {
listen 80;
server_name old_domain.com www.old_domain.com;
return 301 http://new_domain.com$request_uri?;
}
Or if inside server block:
if ($request_uri = / ) {
rewrite (.*) http://new_domain.com/ permanent;
}
I have a simple index.html page with some javascript.
On my nginx config, I would like to apply this rule :
Rewrite http://www.mywebsite.com/?l=A1B2C3 to http://www.mywebsite.com/A1B2C3
Here is my file (I got a 500 error) :
server {
listen 80;
root ...;
index index.html;
server_name www.mywebsite.com;
location / {
rewrite ^(.*)$ /?l=$1 last;
break;
}
}
Try this:
location / {
rewrite ^/([A-Za-z0-9_]+)$ /?l=$1 last;
}
I have a redirection:
server {
server_name mydomain.com;
rewrite ^(.*) http://myanotherdomain.net/image$1 permanent;
}
Everything is ok when I go in mydomain.com/exemple, but how to point mydomain.com where I want ?
I want:
mydomain.com/test -> myanotherdomain.net/image/test (or other than "test") and
mydomain.com -> myanotherdomain.net
Is it possible ?
server {
server_name mydomain.com;
location = / {
return 301 http://myanotherdomain.net;
}
location / {
return 301 http://myanotherdomain.net/image$request_uri;
}
}