我想创建重写规则,捕获几个网址并重定向它们,具体取决于内容在第一个位置是否可用。如果没有,那么在应用程序上调用一个url,以便它重新生成它(下次我们可以从硬盘驱动器访问它)。
让我在这里插入代码,以便更容易理解:
# I need to catch more than one page (and it has to work with and without the trailing slash!)
RewriteCond %{REQUEST_FILENAME} ^(/?|/page1/?|/page2/subpage/?)$ [NC]
# If the content exists
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" -f
# Go to the exported folder and try to serve the page from there
# The first slash problem is here: if I have trailing slash, it will not work, because it will try to go here: /var/www/contentstatic/export/sites/default/$1//index.html
RewriteRule ^(.*)$ /var/www/contentstatic/export/sites/default/$1/index.html
# Otherwise run this rule (regenerate the file)
# This has to be changed (to something), because this will catch anything, but I need only the paths I defined earlier: ^(/?|/page1/?|/page2/subpage/?)$ <- Also I have to make sure the that last trailing slash is not there
RewriteRule ^(.*)$ http://application1:8080/export/sites/default/$1/index.html [P]
# At the bottom of the VirtualHost, there is another application that catches all the requests by default, so that's why I shouldn't use the "^(.*)$" in the previous RewriteRule
RewriteRule ^/(.*) http://application2:8080/$1 [P]
ProxyPassReverse / http://application2:8080/
我遇到的问题:
我还尝试从url中删除尾部斜杠(如果它在第一个RewriteRule中),但是这个规则:
[^/](.*)[^/]
将url从这个:/ page2 /更改为:age2,所以它删除了斜杠以及第一个和最后一个字符。
是否可以在第3和第4个RewriteRule中使用相同的“^(/?| / page1 /?| / page2 / subpage /?)$”路径而不重复它们?
由于