大网数据广告活动
网站运营与故障问答

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

· 52CE 我爱测

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 [email omitted] DocumentRoot…

问题原文

原帖链接 · Suriyaa · CC BY-SA 3.0

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 [email omitted]
        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 [email omitted]
        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:

已采纳解答

原帖链接 · Suriyaa · CC BY-SA 3.0

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 [email omitted]
        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]

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。