Welcome! Log In Create A New Profile

Advanced

Rewrite Subdomain to URL

Posted by s3raph 
Rewrite Subdomain to URL
March 20, 2014 12:26AM
I've been stuck on this problem for hours and can't seem to get it working despite trying all the various methods I've seen on here.

Basically, I just want to forward my wildcard subdomains to a URL path invisibly. I.e.

http://user1.mysite.com ---> http://www.mysite.com/index.php?user=user1

This is my nginx/sites-available/default file:

server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;
index index.html index.php index.htm;

server_name mysite.com www.mysite.com;

location / {
try_files $uri $uri/ /index.html;
rewrite ^/(((?!products|suppliers|member|wap))[a-z0-9_-]+)([/])?$ /index.php?user=$1;
#rewrite ^(.*)\.mysite\.com/$ $scheme://www.mysite.com/index.php?user=$1 last;

}

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}

server {
server_name ~^(?<subdomain>.+?)\.mysite\.com$;
rewrite ^ $scheme://www.mysite.com/index.php?user=$subdomain;
# I have also tried adding permanent, redirect, last to the line above
}


So I don't know where I'm going wrong... when I enter user1.mysite.com, it will correctly redirect me to my site.com/index.php?user=user1, but the URL in the browser will change, and I don't want to see that... What have I done wrong?

On another note, if I remove $scheme://www.mysite.com and just use /index.php?user=$subdomain; then it wouldn't even redirect...

Please assist. Many thanks in advance!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 128
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready