【问题标题】:Redirect path to home, with path string as a GET variable using .htaccess使用 .htaccess 将路径字符串作为 GET 变量重定向到主页
【发布时间】:2021-04-21 02:28:13
【问题描述】:

我正在尝试动态重定向表单的所有链接

example.com/path1
example.com/path2
example.com/path3
...

example.com?src=path1
example.com?src=path2
example.com?src=path3
...

静态规则如下

Redirect /path1 https://example.com?src=path1

但我想用 每个 可能的字符串来做到这一点。有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    您能否尝试以下,根据显示的示例编写。请确保在测试 URL 之前清除浏览器缓存。

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^(.*)/?$ ?src=$1 [R=301,L]
    

    【讨论】:

    • 完美运行(只要您将最后一行编辑为RewriteRule ^(.*)/?$ https://example.com?src=$1 [R=301,L]。非常感谢!!!
    猜你喜欢
    • 1970-01-01
    • 2011-04-02
    • 2018-12-02
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 2013-10-22
    • 2013-08-06
    相关资源
    最近更新 更多