【问题标题】:Rewrite URL and redirect base url using htacesss使用 htaccess 重写 URL 和重定向基本 url
【发布时间】:2021-10-06 07:45:18
【问题描述】:

我是 htaccess 重写规则和正则表达式的新手 我想重写我的基地 网址 -> /service/authentication/?step=1 到 -> /service/new/auth/1

step= 是从 1 到 5 的参数

所以我的规则是:

RewriteRule ^new/auth/([^/.]+)?$ /service/index.php/authentication/?step=$1 [L]
RewriteRule ^new/auth/([^/.]+)?/$ /service/index.php/authentication/?step=$1 [L]

所以当我在 url 中访问 /service/new/auth/8 时效果很好

所以在那之后我创建了一个新规则来将基本 url 重定向到重写的 url

我的规则是:

RewriteRule ^authentication/$ /service/new/auth/$1 [L,R]

基本网址现在重定向到/service/new/auth/?step=1

它必须重定向到 /service/new/auth/1 而不显示 step=1 和 ?必须是id

我认为我的 regax 有问题

感谢大家的帮助

【问题讨论】:

    标签: regex .htaccess redirect mod-rewrite


    【解决方案1】:

    对于您显示的示例,请尝试遵循 htaccess 规则。确保将这些规则放在重写规则之前(我假设您的文件中已经存在)。

    确保在测试您的 URL 之前清除您的浏览器缓存。

    RewriteEngine ON
    ##Rules for external redirect goes from here....
    RewriteCond %{THE_REQUEST} \s/service/authentication\?step=(\d+)\s
    RewriteRule ^ /service/new/auth/%1? [R=301,L]
    ##rest of your rules for internal redirect/rewrite goes from here..
    

    【讨论】:

    • 我尝试了你的解决方案,但仍然是同样的问题
    • @adnenmanssouri,请告诉我您访问的是哪个示例 URL?您遇到什么错误?
    • 当我输入重写的 url 时它工作正常 (/service/new/auth/1) 但是当我转到基本 url (/service/authentication/?step=1) 时它必须重定向到重写的 url,但它重定向到(到 (/service/new/auth/?step=1) 但没有 id 和 step=1 一定不能显示
    猜你喜欢
    • 2017-06-16
    • 2015-07-28
    • 1970-01-01
    • 2012-03-14
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2013-01-27
    相关资源
    最近更新 更多