我想知道这在 mod_rewrite 中是否可行,以及是否有人知道它的语法。
浏览器接收:
http://example.com/video/my-first-vid/
mod_rewrite 重定向到:
http://example.com/#/video/my-first-vid/
谢谢!
我想知道这在 mod_rewrite 中是否可行,以及是否有人知道它的语法。
浏览器接收:
http://example.com/video/my-first-vid/
mod_rewrite 重定向到:
http://example.com/#/video/my-first-vid/
谢谢!
我不确定是否在 URI 中嵌入“#”,因为这通常是一个片段标识符,但您可以试试这个:
RewriteRule "^(?<!#/)(.*)" "#/$1" [R=301,L]
这应该将前面没有“/#”的任何内容重定向到前面有“/#”的相同位置。
看来您不能使用 mod_rewrite 重定向到/#/video/my-first-vid/因为 # 符号是 urlencoded 并且它将重定向到http://example.com/%23/video/my-first- vid/这显然不是你要找的。这几天我在 Apache 1.3 上进行了测试。
您可以为重定向创建一个单独的脚本。为此添加新规则:
RewriteRule ^video/?$ /redirector.php?page=video [NC,L,QSA]
RewriteRule ^video/(.*)$ /redirector.php?page=video&subpage=$1 [NC,L,QSA]
但是您可能还需要手动解析查询字符串,因为它可能是这样的:
/video/my-first-vid/?refID=test
下面是一些关于 PHP 的简单示例:
<?php
$page = (isset($_REQUEST["page"])) ? trim($_REQUEST["page"]) : "";
$subPage = (isset($_REQUEST["subpage"])) ? trim($_REQUEST["subpage"]) : "";
// setting the redirect URL, your conditions here
if ($page == "video")
{
$url = "/#/video/" . $subPage;
}
else
{
$url = "/"; // some default url
}
header("Location: " . $url);
exit;
?>