【问题标题】:How to add a redirection from main url to url-on-sub-domain?如何添加从主 url 到 url-on-sub-domain 的重定向?
【发布时间】:2012-06-28 14:04:58
【问题描述】:

我为网站new4u.com 创建了一个sub-domain forum.new4u.com

其实是/web/forum目录下的论坛。所以论坛也可以通过http://news4u.com/forum/index.phphttp://forum.news4u.com/index.php 访问

现在,我想将所有旧论坛 URL 重定向到新论坛 URL。

示例:

http://news4u.com/forum/post_id=225

http://forum.news4u.com/post_id=225

我怎样才能实现它。

【问题讨论】:

    标签: .htaccess redirect url-rewriting http-status-code-301


    【解决方案1】:

    取决于您的服务器技术。

    IIS - ISAPI Rewrite

    Apache - mod_rewrite

    nginx - HttpRewriteModule

    编辑 -

    既然你应该使用 mod_rewrite,你可以这样做:

    RewriteRule ^forum/([^/.]+) http://forum.news4u.com/$1
    

    EDIT2 -

    RewriteCond %{HTTP_HOST} ^forum.news4u.com [NC]
    RewriteRule ^/(.*)$ /forum/$1 [L]
    

    【讨论】:

    • 嗨..我将它添加到 .htaccess 中并且它正在被重定向。但是以这种方式给出错误forum.news4u.com/index 的网页导致了太多的重定向。在输入forum.news4u.com/index.php 后,它只需要forum.news4u.com/index
    • 对不起,我的第一个答案有点倒退。添加了一个更好、更少错误的解决方案。
    • 很抱歉再次打扰您..我又出错了...通过粘贴edit 2代码,我没有被重定向..
    猜你喜欢
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多