【问题标题】:Apache RewriteRule without trailing slash(/)Apache RewriteRule 不带斜杠(/)
【发布时间】:2019-04-07 06:08:07
【问题描述】:

我正在尝试使用 .htaccess 重定向 URL,如下所示:

example.io/foo => example.io/~user/foo
example.io/foo/ => example.io/~user/foo/

我试过了:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(example\.io) [NC]
RewriteRule ^(.*)/?$ /~user/$1 [L]

</IfModule>

当我访问example.io/foo/时,它响应[200],浏览器显示example.io/foo/

但是当访问example.io/foo时,响应[301]并显示example.io/~user/foo



当我访问example.io/foo时,我希望浏览器显示example.io/foo(不带斜线)

【问题讨论】:

    标签: url url-rewriting apache2


    【解决方案1】:

    要实现这一点:

    example.io/foo => example.io/~user/foo
    example.io/foo/ => example.io/~user/foo/
    

    你应该这样做:

    RewriteCond %{REQUEST_URI} ^/foo/ [OR]
    RewriteCond %{REQUEST_URI} ^/foo
    RewriteRule ^(.*)$ ~user/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 2023-03-23
      • 2016-04-29
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 2011-09-13
      • 2019-03-01
      • 1970-01-01
      相关资源
      最近更新 更多