Answer the question
In order to leave comments, you need to log in
Nginx+drupal7+landing pages how to properly set up a redirect?
Hello. There is such a task:
about 400 domains of the same type that differ in endings, for example:
examlpe.com
example.net
examples.com
examples.net
All four requests must be redirected to example.com/?q=example
Current config version:
set $main_host 'example.com';
if ($host != $main_host) {
rewrite ^(.*)$ http://$main_host/?q=example$1 redirect;
break;
}
if ($host = $main_host) {
rewrite http://$main_host http://$main_host/?q=example$1 redirect;
break;
}
rewrite ^ $scheme://example.com\?q=example break;
return 301 $scheme://example.com\?q=example$request_uri;
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)parts\.com [NC]
RewriteRule (.*)$ http://%1part.com [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)parts\.net [NC]
RewriteRule (.*)$ http://%1part.com [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)\.net [NC]
RewriteRule (.*)$ http://%1.com [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)\.COM [NC]
RewriteRule ^$ index.php?q=%1 [NC,QSA]
if ($http_host ~ "^(.*)parts.com"){
set $rule_0 1$rule_0;
set $bref_1 $1;
}
if ($rule_0 = "1"){
rewrite /(.*)$ http://$bref_1part.com permanent;
}
if ($http_host ~ "^(.*)parts.net"){
set $rule_2 1$rule_2;
set $bref_1 $1;
}
if ($rule_2 = "1"){
rewrite /(.*)$ http://$bref_1part.com permanent;
}
if ($http_host ~ "^(.*).net"){
set $rule_3 1$rule_3;
set $bref_1 $1;
}
if ($rule_3 = "1"){
rewrite /(.*)$ http://$bref_1.com permanent;
}
if ($http_host ~* "^(.*).COM"){
set $rule_4 1$rule_4;
set $bref_1 $1;
}
if ($rule_4 = "1"){
rewrite ^/$ /index.php?q=$bref_1;
}
Answer the question
In order to leave comments, you need to log in
I don't understand why this is so stupid.
server {
listen 80;
server_name .example.*;
if ($arg !~ q=example) { rewrite ^(.*)$ http://example.com/?q=example$1 redirect; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question