How to redirect in local domain web site www.mydomain.com/website to www.mydomain.com
I have install simple web service (MediaWiki) in my local server. In my DSN server I have set IP address to this webserver, so now when I call in browser (this works only in my domain IP range) I get website of Apache, when I call then my site of mediawiki is open.
Can I make that in browser (still I whant this to work only in domain range) I call that opens - redirects to ?
01 Answer
For this purposes you need to change the content of default Virtual Host configuration file 000-default.conf that is located in /etc/apache2/sites-available/. Or you can create a new Virtual Host configuration file, then you must disable 000-default.conf and enable the new one.
Let's assume you decide to create a new VH configuration file, lets call it my.wiki.org.conf, it should be located in /etc/apache2/sites-available/ and its content should be something as:
<VirtualHost *:80> ServerName my.wiki.org ServerAdmin # According MWiki Manual:Security php_flag register_globals off ErrorLog ${APACHE_LOG_DIR}/my.wiki.org.error.log CustomLog ${APACHE_LOG_DIR}/my.wiki.org.access.log combined <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> DocumentRoot "/var/www/my.wiki.org" <Directory "/var/www/my.wiki.org"> Options None FollowSymLinks #Allow .htaccess: AllowOverride All Require all granted </Directory> # According to MWiki Manual:Security <Directory "/var/www/"> Options -Indexes # Allow .htaccess files AllowOverride All # Serve HTML as plaintext, don't execute SHTML AddType text/plain .html .htm .shtml .php .phtml .php5 # Don't run arbitrary PHP code. php_admin_flag engine off # If you've other scripting languages, disable them too. </Directory> # According to MWiki Manual:Security <Directory "/var/www/"> Deny from all AllowOverride AuthConfig Limit Require local </Directory>
</VirtualHost>Then disable 000-default.conf, enable my.wiki.org.conf and restart (or reload) Apache's configuration:
sudo a2dissite 000-default.conf
sudo a2ensite my.wiki.org.conf
sudo systemctl restart apache2.serviceThe key point here is that you changed DocumentRoot of the Virtual Host to the installation directory of MediaWiki. I assuming here this directory is /var/www/my.wiki.org.
In addition if you want to serve your wiki articles by , instead of , you can add the following lines in the .htaccess file, located in the DocumentRoot directory:
<ifModule mod_rewrite.c> RewriteEngine On RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
</ifModule>And modify your LocalSettings.php as follow:
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";References about this additional part:
For test purposes you could add some lines, as the shown below, in your /etc/hosts file to access your wiki via FDQN instead of localhost or IP address in your LAN (more details):
127.0.0.1 localhost my.wiki.org # access my.wiki.org from the same machine
192.168.0.150 my.wiki.org # access my.wiki.org that is hosted on another LAN machine with IP 192.168.0.150One more security note for public servers:
- I would enable HTTPS and would redirect all users to it.
Read also: