如何将没有标题的 Mediawiki 短 URL 重定向到主页? [英] How to redirect Mediawiki Short URL with no title to Main Page?

查看:19
本文介绍了如何将没有标题的 Mediawiki 短 URL 重定向到主页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的 mediawiki 实现了短 URL,我在 htaccess 中有这些:

I've implemented Short URL for my mediawiki and I have these in htaccess that works:

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

如何将没有页面标题的页面 url 重定向到 Main_Page?喜欢将 mysite.com/wiki/重定向到 mysite.com/w/index.php/Main_Page?在 MW Apache 重写手册中,它说:

How do I redirect page urls that doesnt have page title to Main_Page? Like redirecting mysite.com/wiki/ to the mysite.com/w/index.php/Main_Page? In the MW Apache rewrite Manual it says this:

或者,您可以包含一个规则来在路径上显示主页本身,当人们访问没有页面的 url 时简化导航指定标题:

Optionally, you can include a rule to show the Main Page on the path itself, to simplify navigation when people visit urls without a page title specified:

# Redirect/to Main Page RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

当我添加上述内容时,主域地址被重定向到我不想要的 wiki,因为我有一个不同的主页而不是 wiki.我只想重定向看起来像 mysite.com/wiki

When I add the above, the main domain address gets redirected to wiki which I dont want since I have a different Home Page and not wiki. I only want to redirect the address that looks like mysite.com/wiki

我尝试过这种重写,但它不起作用.

I tried this rewrite but it doesnt work.

RewriteRule ^/?wiki/?$ %{DOCUMENT_ROOT}/w/index.php [L]

显然我搞错了.请问有人可以看看吗?

Obviously I got something wrong. Can someone look at this please?

推荐答案

这个重定向规则应该会自动将没有页面标题的 url 像/wiki/重定向到 wiki/Main_Page :

This redirect rule should automatically take care of redirecting urls with no page title like /wiki/ to the wiki/Main_Page too:

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

它之前对我不起作用,因为在此之前还有其他重写规则.一旦我将此重写规则移到所有其他重写规则之前的顶部,它就起作用了.

It wasnt working for me before since there was other rewrite rules before this. It worked once I move this rewrite rule to the top before all other rewrite rules.

这篇关于如何将没有标题的 Mediawiki 短 URL 重定向到主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆