【问题标题】:Redirect all subdirectory pages to new domain home page in .htaccess将所有子目录页面重定向到 .htaccess 中的新域主页
【发布时间】:2017-03-08 10:25:07
【问题描述】:

我想将 olddomain.com/subdirectory/ 下的所有页面重定向到 newdomain.com

newdomain.com 站点具有新的 URL 结构,因此我希望将 olddomain.com/subdirectory/urls 下的每个页面重定向到 newdomain.com主页。

我试过下面的代码。

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain.com/subdirectory/$ [NC]
RewriteRule ^(.*)$ http://newdomain.com [R=301,L]
</IfModule>

但它使用现有网址(如http://newdomain.com//url)重定向,并通过 404 错误。

高度赞赏任何帮助。谢谢

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以使用以下规则:

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^subdir/(.*)$ http://newdomain.com/ [R=301,L]
    </IfModule>
    

    【讨论】:

    • 如果有人对此代码有疑问,请尝试将其放在 .htaccess 文件的顶部。这对我有用。
    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    相关资源
    最近更新 更多