You can add this in your nginx config, in a server block. Anyone using www in the URL will have it removed for them. We also follow rewrite rules 
http://wiki.nginx.org/Pitfalls#Taxing_Rewrites
server {
server_name www.mydomain.com;
rewrite ^ http://mydomain.com$request_uri? permanent;
}
// end rewrite
server {
server_name mydomain.com;
...
}
I wanted to use a short URL in a mediawiki install, eg; www.mywiki.com/article-name.
I’ve installed the mediawiki script in the root folder of my website. The LocalSettings.php file contains the relevant info;
## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = '/$1';
$wgUsePathInfo = true;
Your mileage may vary but you’d need a similar config as below for nginx.
http://wiki.nginx.org/MediaWiki
server {
# rewrite from www.example.com to example.com
server_name www.gorewiki.com;
rewrite ^(.*) http://yourwiki.com$1 permanent;
}
server {
server_name www.yourwiki.com;
root /srv/www/yourwiki.com/public_html;
index index.php index.html;
client_max_body_size 5m;
client_body_timeout 60;
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?title=$1&$args;
}
location ^~ /maintenance/ {
return 403;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
try_files $uri /index.php;
expires max;
log_not_found off;
}
location = /_.gif {
expires max;
empty_gif;
}
location ^~ /cache/ {
deny all;
}
}
After restarting nginx all works well with our “pretty” short URL structure on the wiki.