【问题标题】:htaccess redirect with and without parameters带参数和不带参数的 htaccess 重定向
【发布时间】:2014-11-18 21:28:13
【问题描述】:

我正在尝试执行以下重定向:

  • 如果用户来自:www.example.com/folder/sub-folder/,则会重定向到www.example.com/filehtml.html

    这工作正常。

  • 如果用户来自:www.example.com/folder/sub-folder/index.html,则会被重定向到www.example.com/filehtml.html

    这不起作用。

  • 如果用户来自:www.example.com/folder/sub-folder/?id=1&id2=2,会被重定向到www.example.com/filehtml.html?id=1&id2=2

    这工作正常。

  • 如果用户来自:www.example.com/folder/sub-folder/index.html?id=1&id2=2,则会被重定向到www.example.com/filehtml.html?id=1&id2=2

    这不起作用。


Redirect 301 /folder/sub-folder/ /filehtml.html
RewriteCond %{HTTP_HOST}  ^www\.site\.pt$ [NC]
RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^folder/sub-folder/index\.html$ http://www.example.com/filehtml.html%{REQUEST_URI} [R=301,NC]

我做错了什么?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting url-redirection


    【解决方案1】:

    用这条规则替换你的所有代码:

    RewriteEngine On
    
    RewriteRule ^folder/sub-folder/ /filehtml.html [L,NC,R=302]
    

    QUERY_STRING 会自动转移到/filehtml.html。

    • 确保将其放在根 .htaccess 中
    • 确保这是第一条规则

    【讨论】:

    • 不起作用。我的 htaccess 有很多规则,其中一些需要与此示例类似。
    • 正如我所建议的,这需要作为第一条规则放置,并且必须位于根 .htaccess 中。 /folder/ 或 /folder/sub-folder/ 中是否还有 .htaccess?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    相关资源
    最近更新 更多