Mediawiki实现短链接伪静态:修订间差异
来自维基鲸
(创建页面,内容为“=== 一、Apache和Nginx配置 === ==== 1.程序位于根目录/ ==== '''Apache: .htaccess 文件''' <pre> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/(.*)$ /index.php?title=$1 RewriteRule ^/*$ /index.php RewriteRule ^(.*)$ /index.php </pre> '''Nginx:''' <pre> location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?title=$1; } rewrite ^/*$ /index.php; rewrite ^(.*)…”) |
无编辑摘要 |
||
第74行: | 第74行: | ||
[[category:mediawiki]] | [[category:mediawiki]] | ||
[[category:wiki]] |
2024年4月9日 (二) 19:00的版本
一、Apache和Nginx配置
1.程序位于根目录/
Apache: .htaccess 文件
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/(.*)$ /index.php?title=$1 RewriteRule ^/*$ /index.php RewriteRule ^(.*)$ /index.php
Nginx:
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?title=$1; } rewrite ^/*$ /index.php; rewrite ^(.*)$ /index.php; }
2.程序位于根目录/wiki/
Apache: .htaccess 文件
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^wiki/(.*)$ wiki/index.php?title=$1 RewriteRule ^wiki/*$ wiki/index.php RewriteRule ^wiki$ wiki/index.php
Nginx:
location / { if (!-e $request_filename){ rewrite ^/wiki/(.*)$ /wiki/index.php?title=$1; } } location /wiki { rewrite ^/wiki/*$ /wiki/index.php; } location = /wiki { rewrite ^(.*)$ /wiki/index.php; }
二、LocalSettings.php配置
打开 Wiki 程序下的 LocalSettings.php ,在末尾加上如下代码。
$wgArticlePath = "/wiki/$1"; $wgUsePathInfo = true;
如果需要修改程序其他动作,可添加如下代码。
$wgArticlePath = "/wiki/$1"; $wgUsePathInfo = true; $actions = ['edit', 'watch', 'unwatch', 'delete','revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info']; foreach($actions as $action) { $wgActionPaths[$action] = "/wiki/$action/$1"; } $wgActionPaths["view"] = "/wiki/$1";