我在一个文件中有一个RewriteMap,并且想要处理(忽略)可选的尾随奴隶。我想尽量减少尾随斜杠的重定向次数。如何更改apache-config?
配置:
<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发布于 2019-09-12 15:21:07
试试这个:
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 ^/(.*?)/$ /$1https://stackoverflow.com/questions/57901838
复制相似问题