Mediawiki Remove index.php: Difference between revisions

From CompleteNoobs
Jump to navigation Jump to search
(Created page with "==Info== My mediawiki is installed in path <b>/var/www/html/noobs</b> and i want to remove the <b>index.php</b> from the URL ==Apache2 config== This apache2 config file is from a localwiki:<br> Note the Path of <b>DocumentRoot</b><br> Inside the Directory angle brackets, note path and make sure:<br> :* <b>Options Indexes FollowSymLinks</b><br> :* <b>AllowOverride All</b><br> make sure they are included: <pre> <VirtualHost *:80> DocumentRoot /var/www/html/noobs...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==Info==
==Info==
My mediawiki is installed in path <b>/var/www/html/noobs</b> and i want to remove the <b>index.php</b> from the URL
My mediawiki is installed in path <b>/var/www/html/noobs</b> and i want to remove the <b>index.php</b> from the URL
'''NOTE:''' [[Host_Your_Own_Mediawiki_Online_Ubuntu_22.04#Remove_index.php_from_URL|This method worked]] The method on this page was to go completenoobs.com/Main_Page - completenoobs.com/noobs/Main_Page maybe better.
There was a bug on this page - do not use: use the link to working method in link above!


==Apache2 config==
==Apache2 config==

Latest revision as of 22:55, 23 April 2023

Info

My mediawiki is installed in path /var/www/html/noobs and i want to remove the index.php from the URL

NOTE: This method worked The method on this page was to go completenoobs.com/Main_Page - completenoobs.com/noobs/Main_Page maybe better.

There was a bug on this page - do not use: use the link to working method in link above!

Apache2 config

This apache2 config file is from a localwiki:
Note the Path of DocumentRoot
Inside the Directory angle brackets, note path and make sure:

  • Options Indexes FollowSymLinks
  • AllowOverride All

make sure they are included:

<VirtualHost *:80>
        DocumentRoot /var/www/html/noobs
    <Directory /var/www/html/noobs>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

DocumentRoot /var/www/html/noobs: This line sets the document root directory for the virtual host. The document root is the top-level directory that contains your web content (HTML, CSS, JavaScript, etc.). In this case, the document root is set to /var/www/html/noobs.

<Directory /var/www/html/noobs>: This line begins a configuration block for the /var/www/html/noobs directory. The settings within this block apply to the specified directory and its subdirectories.

Options Indexes FollowSymLinks: This line sets two options for the directory:

  • Indexes: If a requested directory does not have an index file (e.g., index.html or index.php), the server will generate a directory listing for the browser.
  • FollowSymLinks: The server will follow symbolic links in this directory, allowing it to serve files linked from other locations.

AllowOverride All: This line allows the use of .htaccess files in the /var/www/html/noobs directory and its subdirectories. .htaccess files provide a way to modify the configuration on a per-directory basis, overriding the settings specified in the main Apache configuration files. The All value means that all types of overrides are allowed.

Require all granted: This line controls access to the /var/www/html/noobs directory. In this case, it allows access to everyone, meaning there are no access restrictions for this directory.

</Directory>: This line closes the <Directory> configuration block.

.htaccess file

/var/www/html/noobs/.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This .htaccess file contains a set of mod_rewrite rules for URL rewriting. Let's go through each line and explain its purpose:

  • RewriteEngine On: This line enables the URL rewriting engine (mod_rewrite) for this directory.
  • RewriteBase /: This line sets the base URL for per-directory rewrites. In this case, the base URL is set to /, which means that all rewritten URLs will be relative to the root directory.
  • RewriteRule ^index\.php$ - [L]: This line is a rewrite rule that matches any request starting with index.php. The - in the rule means "do nothing" (i.e., don't rewrite the URL). The [L] flag tells the rewrite engine that this is the last rule to be processed if the current request matches this rule. In other words, if a request is for index.php, it won't be processed by any further rewrite rules.
  • RewriteCond %{REQUEST_FILENAME} !-f: This line is a rewrite condition that checks if the requested file (%{REQUEST_FILENAME}) does not exist (!-f). This condition must be met for the subsequent rewrite rule to be executed.
  • RewriteCond %{REQUEST_FILENAME} !-d: This line is another rewrite condition that checks if the requested file is not a directory (!-d).

LocalSettings.php

/var/www/html/noobs/LocalSettings.php

# rewriteURL
$wgScriptPath = "";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;

These lines in the LocalSettings.php file of MediaWiki configure the URL structure and path settings for your wiki. Let's go through each line and explain its purpose:

  • $wgScriptPath = "";: This line sets the base URL path for accessing MediaWiki's PHP scripts. In this case, the path is set to an empty string, which means the scripts are located in the root directory of the webserver (e.g., http://example.com/index.php). If your MediaWiki installation is in a subdirectory, you would set this value to the subdirectory's path (e.g., $wgScriptPath = "/my-wiki" for http://example.com/my-wiki/index.php).
  • $wgArticlePath = "/$1";: This line sets the URL structure for article pages. The $1 placeholder is replaced by the article's title. In this case, the article path is set to /$1, which means article URLs will look like http://example.com/Article_Title. If you want to include a subdirectory in the article path, you can set this value accordingly (e.g., $wgArticlePath = "/wiki/$1" for http://example.com/wiki/Article_Title).
  • $wgUsePathInfo = true;: This line enables or disables the use of "pretty" URLs with path info. When set to true, MediaWiki uses path info to create clean, readable URLs (e.g., http://example.com/Article_Title). If set to false, MediaWiki uses query strings for URLs (e.g., `http://example.com/index.php

Enable Apache2 rewrite module

Make sure the apache2 rewrite module is enabled with:
a2enmod rewrite

Restart apache2 for changes to take effect:
systemctl restart apache2