【问题标题】:htaccess Redirect everything except subdomain and folderhtaccess 重定向除子域和文件夹之外的所有内容
【发布时间】:2013-11-21 12:13:37
【问题描述】:

我正在尝试将我的整个域 www.example.de 重定向到 www.domain.de/artikel.html,但 3 个子域(以及其中的所有内容)和 2 个文件夹(以及其中的所有内容)除外:

RewriteCond %{REQUEST_URI} !^/folder1/subfolder2/?$ [NC]
RewriteCond %{REQUEST_URI} !^/folder2/?$ [NC]
RewriteCond %{HTTP_HOST} !^static1\.example\.de$ [NC]
RewriteCond %{HTTP_HOST} !^static2\.example\.de$ [NC]
RewriteCond %{HTTP_HOST} !^static3\.example\.de$ [NC]
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.de [NC]
RewriteRule ^(.*)$ http://www.domain.de/artikel.html [R=301,L]

但它只是将带有 www.example.de 的所有内容重定向到 www.domain.de/artikel.html,但不会为 http://example.de 重定向任何内容。

有人给我提示或解决方案吗? 谢谢!

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect subdomain


    【解决方案1】:

    问题在于这种情况会导致重定向仅针对子域发生:

    RewriteCond %{HTTP_HOST} ^(\w+)\.example\.de [NC]
    

    将其替换为:

    RewriteCond %{HTTP_HOST} (\.|^)example\.de [NC]
    

    如果您的 htaccess 仅附加到一个站点 (example.de),您可以完全删除它

    您的 htaccess 将是:

    RewriteCond %{REQUEST_URI} !^/folder1/subfolder2/?.*$ [NC]
    RewriteCond %{REQUEST_URI} !^/folder2/?.*$ [NC]
    RewriteCond %{HTTP_HOST} !^static1\.example\.de$ [NC]
    RewriteCond %{HTTP_HOST} !^static2\.example\.de$ [NC]
    RewriteCond %{HTTP_HOST} !^static3\.example\.de$ [NC]
    RewriteCond %{HTTP_HOST} (\.|^)example\.de [NC]
    RewriteRule .* http://www.domain.de/artikel.html [R=301,L]
    

    【讨论】:

    • 它有助于解决 www/non-www 问题。但我仍然有一个大问题:它只排除文件夹。但不是该文件夹中的文件。例如:我无法打开 www.example.de/folder2/main.php
    • 我部分修复了它:RewriteCond %{REQUEST_URI} !^/de/qm/(.*)?$ [NC] RewriteCond %{REQUEST_URI} !^/contao/(.*)?$ [NC] RewriteCond %{REQUEST_URI} !^/system/(.*)?$ [NC] RewriteCond %{REQUEST_URI} !^/tl_files/(.*)?$ [NC] 现在它适用于 www.example.de/folder2/main.php 但不适用于 www.example.de/folder1/subfolder2/test.html ??
    • 它有效:)。但在我的情况下,问题是,我们将子文件夹域路由回根目录中的 index.php(bc 它是 contao cms)。我还排除了 index.php,之后它运行良好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2016-08-23
    相关资源
    最近更新 更多