apache 我可以去掉URL的'/wiki/'部分吗?

b5buobof  于 2023-08-07  发布在  Apache
关注(0)|答案(1)|浏览(105)

我可以去掉URL的'/wiki/'部分吗?
我创建了自己的MediaWiki作为一个业余爱好项目。我不得不在这篇文章中删除我网站的网址,因为论坛将其标记为垃圾邮件。
最初,我的URL看起来像这样:

https://[website]/Main_Page
https://[website]/edit/Main_Page
https://[website]/history/Main_Page

etc.

字符串
我的.htaccess有这个:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]


我的LocalSettings.php有这个:

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

$wgServer = "[website]";

$wgResourceBasePath = $wgScriptPath;

$actions = array( 'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info' );

foreach ( $actions as $action ) {
    $wgActionPaths[$action] = "/$action/$1";
}


安装Flagged Revisions extension后出现问题。FlaggedRevs使用rest.php。当FlaggedRevs尝试访问这个API时,服务器返回了一个404:https://[网站]/w/rest.php/flaggedrevs/internal/review/Main_Page
事情是这样的:Apache和MediaWiki试图 * 照字面意思 * 加载一个名为“W/rest.php/flaggedrevs/internal/review/Main Page”的wiki文章。换句话说,FlaggedRevs没有加载REST API,而是尝试加载一个不存在的页面,这当然会导致失败。
我尝试了很多东西,还有asked for help at mediawiki.org。然后,我尝试在URL中插入“/wiki/”。令人惊讶的是,这解决了问题!
我的.htaccess变成了:

(...)
RewriteRule ^wiki/(.\*)$ w/index.php?title=$1 \[L,QSA\]
RewriteRule ^wiki$ w/index.php \[L,QSA\]
RewriteRule ^$ w/index.php \[L,QSA\]


我的LocalSettings.php变成了:

$wgArticlePath = "/wiki/$1";
(...)
$wgActionPaths\[$action\] = "/wiki/$action/$1";


从技术上讲,这解决了这个问题。但现在我被这个愚蠢的“wiki”位困在了我的wiki的URL中(https://[website]/wiki/Main_Page)。
我的问题是:有没有办法去掉它?我可以在.htaccess中放置一个规则来帮助Apache找到rest.php,而不是标题为“W/rest.php/*”的页面吗?

9nvpjoqh

9nvpjoqh1#

修正!感谢@student91.解决方案是“重写%{REQUEST_URI}!^/w/rest.php.
完整的.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/w/rest\.php
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]

字符串

相关问题