I need a nginx rewrite rule to rewrite from:
http://some-keyword.example.com
to www.example.com/keyword.php?keyword=$some-keyword
while domain without www
in front still rewrites to www.example.com
and www
isn't taken as a keyword.
Please could you help me to solve this problem, how to write these two rules?
If you meant redirect, then:
server {
server_name ~^(.*)\.example\.com$ ;
rewrite ^ http://www.example.com/keyword.php?keyword=$1 redirect;
}
In the case of rewrite then simply do
server {
server_name example.com ~^(.*)\.example\.com$ ;
rewrite ^ /keyword.php?keyword=$1 break;
# location /keyword.php {
# ....
# }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With