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

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

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

  1. https://[website]/Main_Page
  2. https://[website]/edit/Main_Page
  3. https://[website]/history/Main_Page
  4. etc.

字符串
我的.htaccess有这个:

  1. RewriteEngine On
  2. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  3. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
  4. RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
  5. RewriteRule ^$ w/index.php [L,QSA]


我的LocalSettings.php有这个:

  1. $wgScriptPath = "/w";
  2. $wgArticlePath = "/$1";
  3. $wgScriptExtension = ".php";
  4. $wgUsePathInfo = true;
  5. $wgServer = "[website]";
  6. $wgResourceBasePath = $wgScriptPath;
  7. $actions = array( 'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info' );
  8. foreach ( $actions as $action ) {
  9. $wgActionPaths[$action] = "/$action/$1";
  10. }


安装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变成了:

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


我的LocalSettings.php变成了:

  1. $wgArticlePath = "/wiki/$1";
  2. (...)
  3. $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:

  1. RewriteEngine On
  2. RewriteCond %{REQUEST_URI} !^/w/rest\.php
  3. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  4. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
  5. RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
  6. RewriteRule ^$ w/index.php [L,QSA]

字符串

相关问题