Last modified: 2014-02-12 23:32:52 UTC
Today I turned my computer into a home server, so now I can access my localhost by entering my public IP address, say http://123.123.123.123/ It works fine, I can access my localhost and all the websites stored in it. Then I went to http://localhost/wiki/ and installed a wiki there. It all went fine. However, when I tried to access the wiki from http://123.123.123.123/wiki/, I got redirected to http://localhost/wiki/ So I tried installing the wiki again, this time at http://123.123.123.123/wiki/. What happened was that I could access the wiki through http://123.123.123.123/wiki, but when I went to http://localhost/wiki/, I got redirected to http://123.123.123.123/wiki/ So I looked into LocalSettings.php, and found that the server name (either http://123.123.123.123/ or http://localhost/) was hard coded at $wgServer. I tried changing its value to $wgServer = 'http://' . $_SERVER['SERVER_NAME'], and was glad to find out that now I could access my wiki from both http://123.123.123.123/wiki/ and http://localhost/wiki/ It seems like an easy solution, but I would like other developer's opinion. Should I push this change? Is there some reason I'm not seeing for keeping the server name hard coded? Two notes: * I noticed that if I run the installer from http://localhost/wiki/, then I said, I can't go to http://123.123.123.123/wiki/ without getting redirected, but I CAN go to http://123.123.123.123/wiki/index.php/Main_Page and not get redirected. Also, I can then navigate through the wiki without getting redirected. Same if I run the installer from http://123.123.123.123/wiki/ and then go to http://localhost/wiki/index.php/Main_Page * I tried the same steps with a WordPress installation, and WordPress had no problems.
You could also just remove $wgServer if you want the autodetection. That code is still inside of MW for compatibility. We used to not set wgServer and let the domain name be autodetected all the time. We purposefully changed the installer to now set $wgServer because it can cause problems when not set. And you'd best rethink your praise of WordPress. In this cause WordPress' track record is actually worse. You may not see yourself being redirected. But it's hardcoding complete urls all over the place as you use it. If you actually used WordPress in that state you'd eventually find that your blog is completely messed up. With plenty of links on the blog that are dead on either side you view it from.