Mediawiki 子目录安装

发布于 2024-12-26 17:52:20 字数 1899 浏览 3 评论 0原文

可能的重复: 子目录和子域上的 MediaWiki (但是没有答案,也没有任何提供帮助的回复)

好吧,我正在尝试将 MediaWiki 配置为安装到子目录。我之前使用 mod_rewrite 将其安装到 http://www.example.com/ 上的主域使用 /wiki/Main_Title 的短 URL。

请注意,我也在 HostGator 共享主机,其中有 短网址的特殊规则

我的目录结构如下:

  • / (站点根目录;.htaccess 的位置)
  • /wiki/ (mediawiki 根;LocalSettings.php 的位置)

这是我尝试过的,

.htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\&(.*)$ $1\%26$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.+)$ ./wiki/index.php?title=$1 [PT,L,QSA]

/wiki/LocalSettings。 php:

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
##
$wgScriptPath       = "/wiki";
$wgScriptExtension  = ".php";
$wgArticlePath      = "$wgScriptPath/$1";

但是,我什么也没得到。我只是收到 403/Forbidden 错误;没有 500 内部服务器错误,只是 403 - url http://www.example.com/ example.com/。就好像什么都没做一样。我把头撞在墙上试图解决这个问题。任何帮助表示赞赏。

提前致谢!

Possible Duplicate: MediaWiki on SubDirectory and SubDomain (However doesn't have an answer, nor any replies offering help)

Alright, I'm trying to configure MediaWiki to be installed to a sub-directory. I previously had it installed to a primary domain on http://www.example.com/ with a mod_rewrite using a Short URL of /wiki/Main_Title.

As a note, I'm also on HostGator shared hosting which has special rules for short urls.

My directory structure is as such:

  • / (site root; location of .htaccess)
  • /wiki/ (mediawiki root; location of LocalSettings.php)

Here's what I tried,

.htaccess:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\&(.*)$ $1\%26$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.+)$ ./wiki/index.php?title=$1 [PT,L,QSA]

/wiki/LocalSettings.php:

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
##
$wgScriptPath       = "/wiki";
$wgScriptExtension  = ".php";
$wgArticlePath      = "$wgScriptPath/$1";

However, I do not get anything. I simply get a 403/Forbidden error; no 500 Internal Server Error, just a 403 - url http://www.example.com/. It's as if there's nothing being done. I've banged my head against the wall trying to figure this out. Any help is appreciated.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

奢望 2025-01-02 17:52:20

的目的是什么?

RewriteRule ^(.*)\&(.*)$ $1\%26$2

你在这件事上完全迷失了我。任何带有第二个参数的 URI 将无限循环并生成 500 状态返回。

如果您阅读了 Rewrite 文档:

匹配什么?

...如果您希望匹配 ... 查询字符串,请使用带有 ... %{QUERY_STRING} 变量的 RewriteCond

RewriteCond通常是查询参数的一部分。如果 URI 格式错误(例如 fred&q=1),它可能会出现在 RewriteRule 模式中。默认情况下,mod_rewrite 会将其视为 fred?q=1,但这会将其转换为转义的 %26 变体,因此它将作为标题 fred&q=1 传递> 到 MW(顺便说一句,这是一个无效的 MW 标题)。我认为你应该摆脱它或者至少理解你在这里想做什么。

最后一行应该是

RewriteRule ^wiki/(.+) wiki/index.php?title=$1 [PT,L,QSA]

并保留RewriteBase,否则 mod_rewrite 可能会感到困惑。

这应该可以正常工作:-)

What is the purpose of

RewriteRule ^(.*)\&(.*)$ $1\%26$2

You've lost me entirely on this one. Any URI with a second parameter will loop indefinitely and generate a 500 status return.

If you read the Rewrite documentation:

What is matched?

...If you wish to match against the ... query string, use a RewriteCond with the ... %{QUERY_STRING} variables

The & is normally part of the query parameter. It can appear in the RewriteRule pattern in the case of malformed URI (e.g. fred&q=1). By default, mod_rewrite will treat this as fred?q=1, but this converts it to the escaped %26 variant so this would be passed as a title fred&q=1 to MW (which is an invalid MW title by the way). I think that you should get rid of it or at least understand what you are trying to do here.

The last line should be

RewriteRule ^wiki/(.+) wiki/index.php?title=$1 [PT,L,QSA]

and keep the RewriteBase otherwise mod_rewrite can get confused.

This should work OK:-)

静若繁花 2025-01-02 17:52:20

您走在正确的道路上...如果您在共享环境中,请尝试以下操作:

RewriteEngine on
# Comment to force base to be the subdir:
# RewriteBase /
RewriteRule ^(.*)\&(.*)$ $1\%26$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.+)$ ./wiki/index.php?title=$1 [PT,L,QSA]

两个提示:

如果您不在托管环境中(=如果它是您自己的服务器并且您可以修改虚拟主机,不仅仅是 .htaccess 文件),尝试使用 RewriteLog 指令:它可以帮助您追踪此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

我最喜欢的检查正则表达式的工具:

http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg (PCRE)!)

You're on the right track... if you're on a shared environment, then try this:

RewriteEngine on
# Comment to force base to be the subdir:
# RewriteBase /
RewriteRule ^(.*)\&(.*)$ $1\%26$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.+)$ ./wiki/index.php?title=$1 [PT,L,QSA]

Two hints:

If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

听,心雨的声音 2025-01-02 17:52:20

我的 HostGator 票解决了这个问题,尽管没有什么帮助。我希望有一个单一 .htaccess 解决方案,而不是双重.htaccess 重定向/重写。但是,这是我的解决方案。

/:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ http://www.example.com/wiki/

/wiki/:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]

My ticket to HostGator resolved the issue, albeit un-helpfully. I was hoping for a single .htaccess solution, rather than a double .htaccess redirect/rewrite. However, here's my solution.

/:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ http://www.example.com/wiki/

/wiki/:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]
回眸一遍 2025-01-02 17:52:20

我尝试了不同的解决方案,对我有用的是将 mediawiki 子文件夹中的 .htaccess 更改为

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wikifolder/index.php [L]
</IfModule>

I tried different solutions and what worked for me was changing .htaccess in mediawiki subfolder to

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wikifolder/index.php [L]
</IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文