【问题标题】:Apache Rewriterule with or without slashes on endApache Rewriterule 结尾有或没有斜杠
【发布时间】:2023-03-23 09:56:02
【问题描述】:

我的 .htaccess 文件中有以下 Apache RewriteRule

RewriteRule ^([^\.]+)\/?$ $1.php [NC,L]

但它仅在用户输入没有结尾 / 的 URL 时才有效

例如:www.mydomain.com/contact

这不起作用:www.mydomain.com/contact/

我哪里出错了?

【问题讨论】:

    标签: apache .htaccess mod-rewrite rewrite


    【解决方案1】:

    它不起作用,因为您的正则表达式错误,当您输入 www.domain.com/contact/ 时,这使得 $1 成为 contact/

    将您的规则更改为:

    RewriteRule ^([^/.]+)/?$ $1.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 2016-04-21
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多