0

我在文件中有一个 RewriteMap,并且想要处理(忽略)可选的尾随斜杠。我想尽量减少尾部斜杠案例中的重定向数量。如何更改 apache 配置?

配置:

<VirtualHost *:80>
ServerName redirtest.localhost
RewriteEngine on

RewriteMap test "txt:/tmp/redirects.txt"  #/old   /new
RedirectMatch ^/(.*?)/$ /$1
RewriteCond %{REQUEST_URI}           ^(.*)$
RewriteCond ${test:%1|NOT_PRESENT}  !NOT_PRESENT [NC]
RewriteRule .?                       ${test:%1} [NC,R=301]

结果(好的):

curl -sIL 'http://redirtest.localhost/old?key=val&somemore=foobar' |grep Location 
Location: http://redirtest.localhost/new?key=val&somemore=foobar

下面的作品,但我想避免中间重定向:

curl -sIL 'http://redirtest.localhost/old/?key=val&somemore=foobar' |grep Location
Location: http://redirtest.localhost/old?key=val&somemore=foobar
Location: http://redirtest.localhost/new?key=val&somemore=foobar
4

1 回答 1

1

尝试这个:

RewriteMap test "txt:/tmp/redirects.txt" 
RewriteCond %{REQUEST_URI}           ^(.*\w)/?$
RewriteCond ${test:%1|NOT_PRESENT}  !NOT_PRESENT [NC]
RewriteRule .?                       ${test:%1} [NC,R=301]
RedirectMatch ^/(.*?)/$ /$1
于 2019-09-12T15:21:07.783 回答