I know this must have been answered a million times but I can't seem to get it to work
I would like to redirect a subdomain to a subdirectory.
I am currently using
server {
server_name sub.domain.com;
rewrite ^(.*) http://www.domain.com/sub-directory permanent;
}
If I navigate to sub.domain.com I am redirected to http://www.domain.com
EDIT
Here's my full config. I have changed the actual domains and sub directories
server {
server_name forum.domain.com;
rewrite ^(.*) http://www.domain.com/forum permanent;
}
server {
# Listen on port 80 as well as post 443 for SSL connections.
listen xx.xxx.xxx.xxx:80;
server_name domain.com www.domain.com;
# Path to the files in which you wish to
# store your access and error logs.
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /usr/share/nginx/www;
location /wordpress-blog {
index index.php;
try_files $uri $uri/ /wordpress-blog/index.php?args;
}
#root is a magento ecommerce install
location / {
index index.htm index.php;
try_files $uri $uri/ @handler;
}
#this part makes all pretty urls work for my simple machines forum
location /forum/
{
index index.php index.html;
if (!-e $request_filename)
{
# Rules for: profiles
rewrite ^/burton-snowboard-forum/profile/([^/]+)/?$ "/burton-snowboard-forum/index.php?pretty;action=profile;user=$1" last;
# Rules for: actions
rewrite ^/burton-snowboard-forum/(activate|admin|ads|announce|attachapprove|ban|boardrecount|buddy|calendar|clock)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(collapse|convertentities|coppa|credits|deletemsg|detailedversion|display|dlattach|editpoll|editpoll2)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(emailuser|featuresettings|findmember|groups|help|helpadmin|im|jseditor|jsmodify)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(jsoption|lock|lockvoting|login|login2|logout|manageboards|managecalendar|managesearch|manageattachments|maintain|markasread|mascot)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(membergroups|mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|news|notify)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(notifyboard|optimizetables|openidreturn|packages|permissions|pm|post|postsettings|post2|printpage|profile|quotefast)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(quickmod|quickmod2|recent|regcenter|register|register2|reminder|removepoll|removetopic2)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(repairboards|reporttm|requestmembers|restoretopic|reports|search|search2|sendtopic|serversettings|smileys|smstats|suggest)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(unread|unreadreplies|verificationcode|viewErrorLog|viewmembers|viewprofile|vote|viewquery|viewsmfile|who)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
rewrite ^/burton-snowboard-forum/(\.xml|xmlhttp)/?$ "/burton-snowboard-forum/index.php?pretty;action=$1" last;
# Rules for: boards
rewrite ^/burton-snowboard-forum/([-_!~*'()$a-zA-Z0-9]+)/?$ "/burton-snowboard-forum/index.php?pretty;board=$1.0" last;
rewrite ^/burton-snowboard-forum/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ "/burton-snowboard-forum/index.php?pretty;board=$1.$2" last;
# Rules for: topics
rewrite ^/burton-snowboard-forum/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ "/burton-snowboard-forum/index.php?pretty;board=$1;topic=$2.0" last;
rewrite ^/burton-snowboard-forum/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ "/burton-snowboard-forum/index.php?pretty;board=$1;topic=$2.$3" last;
rewrite ^/(.*)$ /index.php?params=$1 last;
}
}
#Magento configurations
# Deny access to specific directories no one
# in particular needs access to anyways.
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }
# Allow only those who have a login name and password
# to view the export folder. Refer to /etc/nginx/htpassword.
location /var/export/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
autoindex on;
}
# Deny all attempts to access hidden files
# such as .htaccess, .htpasswd, etc...
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# This redirect is added so to use Magentos
# common front handler when handling incoming URLs.
location @handler {
rewrite / /index.php;
}
# Forward paths such as /js/index.php/x.js
# to their relevant handler.
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# Handle the exectution of .php files.
location ~ .php$ {
if (!-e $request_filename) {
rewrite / /index.php last;
}
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE btn;
fastcgi_param MAGE_RUN_TYPE website;
include fastcgi_params;
}
}