【问题标题】:Rewriterule not applied in Apache 2.4 httpd.confRewriterule 未在 Apache 2.4 httpd.conf 中应用
【发布时间】:2017-09-08 07:24:12
【问题描述】:

我想通过 httpd.conf 中启用的 RewriteRule (mod_rewrite) 重定向我的 URL:

https://mysite.domain.tld/index_php_file.php?ab=ident_keys&ac=5GU7VBNAH45DA5

到:

https://mysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac=5GU7VBNAH45DA5

我已经尝试了许多规则但没有运气:

RewriteCond %{HTTP_HOST} hmysite.domain.tld
RewriteRule ^/index_php_file\.php\?ab=ident_keys&ac=$ https://hmysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac= [R=301,L,QSA]

也没有

RewriteCond %{QUERY_STRING} ^ac=(.*)$
RewriteRule ^/?([a-z-0-9-_.]+)$ /$1/index_php_file.php?ab=ident_key_1024&ac=%1 [L,R=301]

似乎要重写网址。

对我所缺少的有什么建议吗?

非常感谢。

【问题讨论】:

    标签: mod-rewrite httpd.conf apache2.4


    【解决方案1】:

    我找到了解决方案,它可能对某人有所帮助。

    RewriteCond %{QUERY_STRING} ac=([A-Z0-9]+)
    RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index_php_file.php?ab=ident_key_1024&ac=$1 [R=301,L]
    

    使用RewriteCond 查找字符串(仅包含大写字符和数字)并将URL RewriteRule 重写为所需格式并附加查询中的变量值就足够了。

    不要忘记在 Apache 中启用 mod_rewrite 模块。当然也需要重启才能生效。

    【讨论】:

      猜你喜欢
      • 2016-12-21
      • 2016-04-06
      • 2020-06-21
      • 2013-05-10
      • 1970-01-01
      • 2018-09-16
      • 2019-05-16
      • 2020-03-16
      • 2015-02-05
      相关资源
      最近更新 更多