Redirectmatch 301 是一个 Mediawiki
Redirectmatch 301 on Mediawiki
我在我的 wiki 站点上使用 Mediawiki 脚本。我现在使用 site.com/Page link 结构。
我以前用过这些 link 结构:
网站.com/index.php/Page
网站.com/index.php?title=页面
我想将旧 link 重定向到新闻。
我是为“/index.php/Page”到“/Page”做的。但我无法将“/index.php?title=Page”更改为“/Page”。
这是我的 .htaccess 文件。你有什么看法?
RewriteEngine On
RewriteBase /
RedirectMatch 301 /index.php/(.*) http://viki.gameofthronestr.com/
RedirectMatch 301 /index.php?title=(.*) http://viki.gameofthronestr.com/
我也试过第4行:
RedirectMatch 301 /index.php\?title\=(.*) http://viki.gameofthronestr.com/
我做错了什么?
要根据查询字符串进行重定向,您必须使用 Rewrite_mod。 RedirectMatch NOT 将您的正则表达式与查询字符串匹配。
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^title=(.*)$
RewriteRule ^index.php$ http://viki.gameofthronestr.com/%1? [L,R=302]
注意:这是临时重定向。将 302 替换为 301 以使其永久重定向。
如果我们查看 RedirectMatch 的文档,我们会发现它与域之后和查询字符串之前的 url 相匹配。您犯了不转义文字点的错误(.
匹配每个字符)。此外,问号表示 "the previous character 0 or 1 times",因此 php?
表示 ph
或 php
。
要使用查询字符串重定向 url,您需要求助于 mod_rewrite。在您的主配置文件中启用它,将 AllowOverride
(docs) 至少设置为 FileInfo,然后重新启动 Apache。然后使用下面的代码
RewriteEngine on
RewriteCond %{QUERY_STRING} ^title=([^&]+)$
RewriteRule ^index\.php$ /%1 [R,L,QSD]
在一切正常后,将 R
标志更改为 R=301
。
我在我的 wiki 站点上使用 Mediawiki 脚本。我现在使用 site.com/Page link 结构。
我以前用过这些 link 结构: 网站.com/index.php/Page 网站.com/index.php?title=页面
我想将旧 link 重定向到新闻。
我是为“/index.php/Page”到“/Page”做的。但我无法将“/index.php?title=Page”更改为“/Page”。
这是我的 .htaccess 文件。你有什么看法?
RewriteEngine On
RewriteBase /
RedirectMatch 301 /index.php/(.*) http://viki.gameofthronestr.com/
RedirectMatch 301 /index.php?title=(.*) http://viki.gameofthronestr.com/
我也试过第4行:
RedirectMatch 301 /index.php\?title\=(.*) http://viki.gameofthronestr.com/
我做错了什么?
要根据查询字符串进行重定向,您必须使用 Rewrite_mod。 RedirectMatch NOT 将您的正则表达式与查询字符串匹配。
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^title=(.*)$
RewriteRule ^index.php$ http://viki.gameofthronestr.com/%1? [L,R=302]
注意:这是临时重定向。将 302 替换为 301 以使其永久重定向。
如果我们查看 RedirectMatch 的文档,我们会发现它与域之后和查询字符串之前的 url 相匹配。您犯了不转义文字点的错误(.
匹配每个字符)。此外,问号表示 "the previous character 0 or 1 times",因此 php?
表示 ph
或 php
。
要使用查询字符串重定向 url,您需要求助于 mod_rewrite。在您的主配置文件中启用它,将 AllowOverride
(docs) 至少设置为 FileInfo,然后重新启动 Apache。然后使用下面的代码
RewriteEngine on
RewriteCond %{QUERY_STRING} ^title=([^&]+)$
RewriteRule ^index\.php$ /%1 [R,L,QSD]
在一切正常后,将 R
标志更改为 R=301
。