1

How to create Short URL in Mediawiki without getting an 403 Forbidden Error in Apache?

My httpd.conf:

#### Wikibase (BETA)
<VirtualHost *>
        ServerName wikibase.isc
        ServerAlias wikibase.isc
        ServerAdmin SuriyaaKudoIsc@users.noreply.github.com
        DocumentRoot "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase"
</VirtualHost>

My MediaWiki's local project name is "wikibase" (with a local dns adress: http://wikibase.isc/).

I use following code for the LocalSettings.php file (located in C:\Server\Apache24\htdocs\inc.isc\farm\mediawiki\wikibase\w):

$wgScriptPath = "/w";
$wgServer = "http://wikibase.isc";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

I also create an .htaccess file in C:\Server\Apache24\htdocs\inc.isc\farm\mediawiki\wikibase:

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# Enable the rewrite engine
RewriteEngine On

# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

I get an 403 Forbidden Error in my Firefox Browser from my local Apache Server 2.4:

Forbidden

You don't have permission to access /C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/index.php on this server.

EDIT:

My new httpd.conf code:

#### Wikibase (BETA)
<VirtualHost *>
        ServerName wikibase.isc
        ServerAlias wikibase.isc
        ServerAdmin SuriyaaKudoIsc@users.noreply.github.com
        DocumentRoot "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase"
</VirtualHost>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/wiki/">
    Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

My Apache server.log file:

[Sun Jan 10 14:40:47.547054 2016] [core:error] [pid 6260:tid 1052] (20023)The given path was above the root path: [client 127.0.0.1:8634] AH00127: Cannot map GET / HTTP/1.1 to file
[Sun Jan 10 14:40:49.665828 2016] [core:error] [pid 6260:tid 1052] (20023)The given path was above the root path: [client 127.0.0.1:8634] AH00127: Cannot map GET / HTTP/1.1 to file
[Sun Jan 10 14:40:51.601607 2016] [core:error] [pid 6260:tid 1052] (20023)The given path was above the root path: [client 127.0.0.1:8634] AH00127: Cannot map GET / HTTP/1.1 to file

My Apache access.log file:

127.0.0.1 - - [10/Jan/2016:14:40:49 +0100] "GET / HTTP/1.1" 403 381
127.0.0.1 - - [10/Jan/2016:14:40:49 +0100] "GET / HTTP/1.1" 403 381 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
127.0.0.1 - - [10/Jan/2016:14:40:51 +0100] "GET / HTTP/1.1" 403 381
127.0.0.1 - - [10/Jan/2016:14:40:51 +0100] "GET / HTTP/1.1" 403 381 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"

Other resources

These resources were not helpful:

1

When you encounter a 403 forbidden error it usually is a problem with directory permissions rather than with .htaccess files and rewrite rules.

The first step is to check your servers error log. The error log often has more information in it than is presented to the user's web browser.

The other thing to try is to check the directory permissions. Make sure that the user Apache is running as has permissions to read and execute index.php in that directory.

  • I tried. 1. I checked the log files of my Apache server. (See my updated post!) 2. I tired to check the directory permissions in httpd.conf file. 3. Where is the problem with my directory permissions in httpd.conf file? – Suriyaa Jan 10 '16 at 13:47
  • "Given path above the root path" is the crux of your problem. Google that for solutions. – Stephen Ostermiller Jan 10 '16 at 14:50
  • I solved it with Require all granted in httpd.conf but now I get an Not Found. The requested URL /wiki/Main_Page was not found on this server. error. :-/ – Suriyaa Jan 15 '16 at 14:42
  • Solved it! I put Alias /wiki C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/index.php into .htaccess but I must put this in httpd.conf file! – Suriyaa Jan 15 '16 at 16:01
  • You could submit that as an answer and accept it which would take this question off our "unanswered" list. (Never mind, I see you already did!) – Stephen Ostermiller Jan 15 '16 at 16:46
1

Solved it!

It's important to use Alias and Require all granted in httpd.conf!


  • The httpd.conf file:

This is the configuration of the Apache Sever 2.4!

#### Wikibase (BETA)
<VirtualHost *>
        ServerName wikibase.isc
        ServerAlias wikibase.isc
        ServerAdmin SuriyaaKudoIsc@users.noreply.github.com
        DocumentRoot "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/"
        Alias /wiki                     C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/index.php
        Alias /wiki/index.php           C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/index.php
        Alias /wiki/load.php            C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/load.php
        Alias /wiki/api.php             C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/api.php
        Alias /wiki/opensearch_desc.php C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/opensearch_desc.php
        Alias /wiki/skins               C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/skins
        Alias /wiki/images              C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/images
</VirtualHost>
Include "conf/wikibase-htaccess.conf"

  • The LocalSettings.php file:

This is the wiki setting file!

$wgScriptExtension = ".php";
$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

  • The wikibase-htaccess.conf file:

This file is included in httpd.conf!

# MediaWiki & Stackoverflow
#<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/">
#    Options None
#    AllowOverride None
#    Order allow,deny
#    Allow from all
#    SSLRequireSSL
#    SSLRequire  %{SSL_CLIENT_S_DN}  =~ m/.*serialNumber=<personnummer>$/
#</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/">
    Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order deny,allow
    Allow from all
    Require all granted
</Directory>

# Source: https://wiki.bitnami.com/Components/Apache/htaccess_configuration
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/cache">
  Deny from all
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/images">
  # Protect against bug 28235
  <IfModule rewrite_module>
    RewriteEngine On
    RewriteCond %{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
    RewriteRule . - [forbidden]
  </IfModule>
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/includes">
  Deny from all
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/languages">
  Deny from all
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/maintenance">
  Deny from all
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/maintenance/archives">
  Deny from all
</Directory>
<Directory "C:/Server/Apache24/htdocs/inc.isc/farm/mediawiki/wikibase/w/serialized">
  Deny from all
</Directory>

  • The .htaccess file:

In the .htaccess file there are two possible working methods!

###################### 1st Method (currently used) #########################

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# Enable the rewrite engine
RewriteEngine On

# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]


###################### 2nd Method (deactivated) #########################

# Enable the rewrite engine
##RewriteEngine On
##RewriteBase /wiki

# Redirect index.php to non index.php
##RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /(.*)index\.php
##RewriteRule ^ %1? [R=301,L]

# Internally rewrite request to index.php
##RewriteCond %{REQUEST_FILENAME} !-f
##RewriteCond %{REQUEST_FILENAME} !-d
##RewriteRule ^(.*)$ index.php?/$1 [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.