Mod 重写使用多个 URL 的维护页面
Mod Rewrite Maintenance page that uses multiple URLs
我有一个站点为单个应用程序使用多个 URL。根据站点的 URL,您将获得不同的内容。我需要创建一个重写规则,根据 URL 用户点击的内容将用户重定向到不同的页面。
例如:
如果用户访问 www.foo.bar,用户将被重定向到 www.foo.bar/maintWWW.html
但是如果用户访问 www.bar.foo 用户将被重定向到 www.bar.foo/maintWWW2.html
请记住,由于我们使用的是相同的应用程序但 URL 不同,因此这 2 个 html 页面需要以不同的方式命名以提供不同的内容。
我设法使用了它,但它只会将两个 URL 重定向到一个页面,
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
我尝试用我想要重定向的站点的实际 URL 替换 %{REQUEST_URI}
,但没有成功。
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.foo.bar !/maintWWW.html$ [NC]
RewriteCond http://www.foo.bar !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.bar.foo !/maintWWW2.html$ [NC]
RewriteCond http://www.bar.foo !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW2.html [R=302,L]
我究竟该如何让它发挥作用?我可以包含多个 URL 以重定向到同一页面吗?最好能考虑到开发和暂存 URLs。再举个例子:
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.foo.bar http://staging.foo.bar http://dev.foo.bar !/maintWWW.html$ [NC]
RewriteCond http://www.foo.bar !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
您需要在您的条件中检查 HTTP_HOST
以检查域,然后基于该域进行重定向。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.bar [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar\.foo [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW2.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW2.html [R=302,L]
如果您有多个主机名或别名可以在您的设置中使用,您可以这样做。
RewriteCond %{HTTP_HOST} ^(www|dev|staging)\.foo\.bar [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
我有一个站点为单个应用程序使用多个 URL。根据站点的 URL,您将获得不同的内容。我需要创建一个重写规则,根据 URL 用户点击的内容将用户重定向到不同的页面。
例如: 如果用户访问 www.foo.bar,用户将被重定向到 www.foo.bar/maintWWW.html 但是如果用户访问 www.bar.foo 用户将被重定向到 www.bar.foo/maintWWW2.html
请记住,由于我们使用的是相同的应用程序但 URL 不同,因此这 2 个 html 页面需要以不同的方式命名以提供不同的内容。
我设法使用了它,但它只会将两个 URL 重定向到一个页面,
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
我尝试用我想要重定向的站点的实际 URL 替换 %{REQUEST_URI}
,但没有成功。
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.foo.bar !/maintWWW.html$ [NC]
RewriteCond http://www.foo.bar !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.bar.foo !/maintWWW2.html$ [NC]
RewriteCond http://www.bar.foo !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW2.html [R=302,L]
我究竟该如何让它发挥作用?我可以包含多个 URL 以重定向到同一页面吗?最好能考虑到开发和暂存 URLs。再举个例子:
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond http://www.foo.bar http://staging.foo.bar http://dev.foo.bar !/maintWWW.html$ [NC]
RewriteCond http://www.foo.bar !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
您需要在您的条件中检查 HTTP_HOST
以检查域,然后基于该域进行重定向。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.bar [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar\.foo [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW2.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW2.html [R=302,L]
如果您有多个主机名或别名可以在您的设置中使用,您可以这样做。
RewriteCond %{HTTP_HOST} ^(www|dev|staging)\.foo\.bar [NC]
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintWWW.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintWWW.html [R=302,L]