我希望将public/xxx.html
重写为/public/test/xxx.html
。但是使用
以下结果导致内部重定向导致它再次发生,依此类推。
RewriteRule ^public/(.+\.html)$ /public/test/$1 [NC,L]`
如何更改URL目录而不会导致无限循环?
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html -> public/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html' -> '/public/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3738f978/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/xxx.html -> public/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3738f978/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3738f978/initial/redir#1] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/xxx.html' -> '/public/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3738f978/initial/redir#1] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3738f978/initial/redir#1] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/xxx.html -> public/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/xxx.html' -> '/public/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3737d938/initial/redir#2] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/xxx.html -> public/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/xxx.html' -> '/public/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37397f48/initial/redir#3] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/xxx.html -> public/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f3739c678/initial/redir#4] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a1088/initial/redir#5] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373a5af8/initial/redir#6] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373aa830/initial/redir#7] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373af778/initial/redir#8] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373b4be8/initial/redir#9] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/test/test -> /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/test/test/test/test/test/test/test/test/test/test/xxx.html -> public/test/test/test/test/test/test/test/test/test/test/xxx.html
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'public/test/test/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/test/test/test/test/test/test/test/test/test/test/xxx.html' -> '/public/test/test/test/test/test/test/test/test/test/test/test/xxx.html'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f373ba1d8/initial/redir#10] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/test/test/test/test/test/test/test/test/test/test/test/xxx.html [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/favicon.ico -> favicon.ico
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+\\.html)$' to uri 'favicon.ico'
[test.sites.example.com/sid#7f8f37058e28][rid#7f8f37378b38/initial] (1) [perdir /var/www/mysite/html_sites/] pass through /var/www/mysite/html_sites/favicon.ico
答案 0 :(得分:1)
是的,它确实是一个无限循环,因为你的模式也匹配重写的URI。
要解决此问题,您可以使用:
RewriteRule ^public/([^/.]+\.html)$ /public/test/$1 [NC,L]
[^/.]+
将匹配public/
下方但不低于public/test/