![](/img/trans.png)
[英]htaccess redirect to http specific urls and all except on http
[英]htaccess redirect all urls except two
目前我正在將所有 URL 重定向到我的index.html
文件:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
我想排除兩個 URL,例如:
www.mydomain.com/i-am-a-domain
www.mydomain.com/super-cool
我發現了幾個排除 URL 的片段,但我無法包含它們,因為它們使用不同的設置(至少我是這么認為的)。
由於RewriteCond
設置條件,我想我必須在這里添加一行。 我試過添加:
RewriteCond %{REQUEST_URI} !/(i-am-a-domain|super-cool)\ [NC]
這不起作用。 我怎樣才能做到這一點?
將您現有的條件更改為:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(index\.html|i-am-a-domain|super-cool)/?$ [NC]
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule ^ /index.html [L,R=302]
但是,如果您在此 .htaccess 中還有其他規則,那么我建議使用THE_REQUEST
變量,該變量在執行某些內部重寫規則后不會被覆蓋。
RewriteCond %{THE_REQUEST} !\s/+(index\.html|i-am-a-domain|super-cool)[?\s/] [NC]
RewriteCond %{THE_REQUEST} !\.(gif|jpe?g|png|css|js)\sHTTP
RewriteRule ^ /index.html [L,R=302]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.