.htaccess目录重定向版本发布

时间:2013-02-24 12:32:18

标签: .htaccess

我有一个让我感到害怕的想法,因为我对htaccess并不是很好。

我有网址http://(www./non-www.)example.com/dir/page/file。 但我想将其重定向到目录root/release/.../dir/page/file

所以

root/.htaccess
root/release/1.0/...
root/release/1.5/...
root/release/2.0/...
root/admin/1.0/...
root/admin/1.5/...
root/admin/2.0/...
etc

如果他们浏览example.com/admin,请转到example.com/admin/2.0。但我觉得棘手的一点是,我不想看到example.com/ad{/ {}}}或example.com/admin/ {{}}}。

或者我可以将两个版本托管release/versionversion

我希望这对某人有意义, 感谢

1 个答案:

答案 0 :(得分:0)

最简单的做法是将example.com/admin这样的网页重定向到example.com/admin/2.0,然后你只需要进行mod重写以返回通用网址。当您增加版本时,只需更改元刷新,因为.htaccess mod-rewrite将具有与您的版本编号系统匹配的reg-ex。

示例:

首先在example.com/admin文件中,在标题中实现元刷新:

<meta http-equiv="refresh" content="0;URL='example.com/admin/2.0'">

现在从2.0(或从任何版本)重新写回到你想去的地方:

#first, we need to define the request, in this case, admin/any number
RewriteCond %{THE_REQUEST} /admin/([0-9]*)
# now we need to make it look like it's just the plain admin page
RewriteRule ^$ /admin [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin /admin/([0-9]*) [L]

你需要修复我的reg-ex比赛以使其成为2&#34;指向&#34; 0