簡體   English   中英

Mediawiki上的Redirectmatch 301

[英]Redirectmatch 301 on Mediawiki

我在Wiki網站上使用Mediawiki腳本。 我現在使用site.com/Page鏈接結構。

我以前使用過以下鏈接結構:site.com/index.php/Page site.com/index.php?title=Page

我想將舊鏈接重定向到新聞。

我做到了“ /index.php/Page”到“ / Page”。 但是我無法將“ /index.php?title=Page”更改為“ / Page”。

這是我的.htaccess文件。 您的意見是什么?

RewriteEngine On
RewriteBase /
RedirectMatch 301 /index.php/(.*) http://viki.gameofthronestr.com/$1
RedirectMatch 301 /index.php?title=(.*) http://viki.gameofthronestr.com/$1

我也在4.行上嘗試過:

RedirectMatch 301 /index.php\?title\=(.*) http://viki.gameofthronestr.com/$1

我究竟做錯了什么?

對於基於查詢字符串的重定向,您必須使用Rewrite_mod。 RedirectMatch與查詢字符串匹配您的正則表達式。

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING}  ^title=(.*)$
RewriteRule ^index.php$    http://viki.gameofthronestr.com/%1? [L,R=302]

注意:這是臨時重定向。 將302替換為301,以使其永久重定向。

如果我們查看RedirectMatch的文檔,就會發現它與域之后和查詢字符串之前的url匹配。 您犯了沒有轉義文字點的錯誤( .匹配每個字符)。 此外,問號的意思是“前一個字符0或1次”,所以php? 表示phphp

要使用查詢字符串重定向網址,您需要使用mod_rewrite。 在主配置文件中啟用它,將AllowOverridedocs )設置為至少FileInfo,然后重新啟動Apache。 然后使用以下代碼

RewriteEngine on

RewriteCond %{QUERY_STRING} ^title=([^&]+)$
RewriteRule ^index\.php$ /%1 [R,L,QSD]

一切正常后,將R標志更改為R=301

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM