【问题标题】:htaccess Redirect all except the specified URLhtaccess 重定向除指定 URL 之外的所有内容
【发布时间】:2021-05-01 16:35:47
【问题描述】:

不能使用 (!) 反向操作,会出现重定向 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]

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    这应该适合你:

    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)\/.*$ 返回true,从而重定向到http://ssvwv.com/。这就是为什么您也需要从第一条规则中跳过/index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-04
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多