【问题标题】:htaccess RewriteRule force to put s in the urlhtaccess RewriteRule 强制将 s 放入 url
【发布时间】:2021-09-13 10:17:48
【问题描述】:

htaccess 文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

RewriteRule ^member  member.html [NC,L]
RewriteRule member/(.*)/(.*)$ member.html?a=$1&b=$2

所以应该像https://example.com/member/query_1/query_2

问题是除非我在 url 的成员词末尾添加 (s) 字符,否则此链接将不起作用

所以工作链接是https://example.com/members/query_1/query_2

除非它返回 404 错误 它在 xamp localhost 中工作正常,但是当我上传到服务器时,我遇到了这个问题。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此代码:

    Options -MultiViews
    RewriteEngine On
    
    RewriteRule ^member/?$ member.html [NC,L]
    
    RewriteRule member/([^/]+)/([^/]+)/?$ member.html?a=$1&b=$2 [L,QSA,NC]
    
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+?)/?$ $1.html [L]
    

    Options -MultiViews 将关闭内容协商服务。选项MultiViews(参见http://httpd.apache.org/docs/2.4/content-negotiation.html)由运行before mod_rewriteApache's content negotiation module 使用,并使Apache 服务器匹配文件的扩展名。因此,如果 /file 是 URL,那么 Apache 将提供 /file.html

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多