【问题标题】:Redirect with .htaccess but getting old URL as parameter使用 .htaccess 重定向但获取旧 URL 作为参数
【发布时间】:2022-01-24 15:58:11
【问题描述】:

我想创建一个 .htaccess 文件来重定向我

https://example.net/@UserNamehttps://example.net/user/index.php?user=UserName,但仅当有 @ 时。

有人可以帮帮我吗?

【问题讨论】:

    标签: apache .htaccess web apache2


    【解决方案1】:

    您可以在 htaccess 文件中使用它:

    RewriteEngine On
    
    RewriteRule ^@([^/]+)/?$ https://example.net/user/index.php?user=$1 [L,R]
    

    这会将example.com/@foobar 形式的URL 重定向到https://example.net/user/index.php?user=foobar,从而更改浏览器地址栏中的URL。但是,如果您不想更改 URL,请改用以下内容

    RewriteEngine On
    
    RewriteRule ^@([^/]+)/?$ /user/index.php?user=$1 [L]
    

    【讨论】:

    • 谢谢,这对我有用。 :)
    猜你喜欢
    • 2015-04-27
    • 2017-09-20
    • 2016-07-29
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2014-08-10
    • 2019-03-26
    相关资源
    最近更新 更多