中的語句和正則表達式有一種方法來將htaccess中的部分主機名正則表達?如果在.htaccess
例如:如果%{HTTP_HOST}
匹配任何的'/\w{2,}\.(?:site|local)/i'
做點什麼
感謝
中的語句和正則表達式有一種方法來將htaccess中的部分主機名正則表達?如果在.htaccess
例如:如果%{HTTP_HOST}
匹配任何的'/\w{2,}\.(?:site|local)/i'
做點什麼
感謝
您可以使用這樣的規則:
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} \w{2,}\.(?:site|local) [NC]
RewriteCond $1 !^(styles\.php|templates|application/views/elements\.php|hello\.txt)
RewriteRule ^((?!index\.php).+)$ index.php/$1 [L]
上Anubhava的建議稍加改變:是的,你可以做,如果使用跳過標誌的梯形邏輯:
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} !\w{2,}\.(site|local)
RewriteRule^ - [skip:4]
# the next four rules will be skipped
希望這有助於。
這是一個個人風格的問題,但我已經拿出了非捕獲條件:這只是一個小小的併發症,沒有任何好處。我也寧願更嚴格的正則表達式,例如!^\w{2,}\.(mysite\.com|local)$
,以便您不會得到意想不到的匹配:-)
感謝您的回答。如果條件爲真,我試圖實現的只是包含下面的代碼。 RewriteRule ^(。*)$ /index.php/$1 [L]對不起,我不工作很多與htaccess和它真的很混淆 – user4094622 2014-11-05 17:31:06
但是,你的規則如何與'if%{HTTP_HOST}'你的問題的一部分? – anubhava 2014-11-05 17:38:21
'if(%{HTTP_HOST} MATCHES'/ \ w {2,} \。(?: site | local)/ i'){RewriteCond $ 1!^(styles \ .php | templates | application/views/elements \ php | hello \ .txt) RewriteRule ^(。*)$ /index.php/$1 [L]}' – user4094622 2014-11-05 17:40:46