htaccess 重定向除指定 URL 之外的所有内容
htaccess Redirect all except the specified URL
不能使用(!)反向操作,会出现重定向URL (http://ssvwv.com):
/1/3/ktrb
不会显示 (index.html)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$
RewriteRule ^(.*)$ http://ssvwv.com/ [L,R=302,NE]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . /index.html [L]
这应该适合你:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(?:index\.html|1/[1-3]/.*)$ [NC]
RewriteRule ^ http://ssvwv.com/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]
问题是最后一条规则重写为 /index.html
并且当 mod_rewrite
再次循环时 URI 变为 /index.html
和 RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$
returns true 从而重定向到 http://ssvwv.com/
。这就是为什么您也需要从第一条规则中跳过 /index.html
。
不能使用(!)反向操作,会出现重定向URL (http://ssvwv.com):
/1/3/ktrb
不会显示 (index.html)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$
RewriteRule ^(.*)$ http://ssvwv.com/ [L,R=302,NE]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . /index.html [L]
这应该适合你:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(?:index\.html|1/[1-3]/.*)$ [NC]
RewriteRule ^ http://ssvwv.com/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]
问题是最后一条规则重写为 /index.html
并且当 mod_rewrite
再次循环时 URI 变为 /index.html
和 RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$
returns true 从而重定向到 http://ssvwv.com/
。这就是为什么您也需要从第一条规则中跳过 /index.html
。