Htaccess-主页的If / esle语句语法

时间:2018-09-12 18:25:08

标签: .htaccess

我想知道正确的语法来检查主页(例如abc.comlocalhost),以便为if/else文件编写.htaccess语句。谢谢。

<If "abc.com" OR "localhost">
    <FilesMatch "\.(css|js|txt)$">
        <IfModule mod_expires.c>
            ExpiresActive Off
        </IfModule>
        <IfModule mod_headers.c>
            FileETag None
            Header unset ETag
            Header unset Pragma
            Header unset Cache-Control
            Header unset Last-Modified
            Header set Pragma "no-cache"
            Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
            Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
        </IfModule>
    </FilesMatch>
</If>
<Else>
    <FilesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
</Else>

1 个答案:

答案 0 :(得分:1)

你的意思是这样吗

<ifModule mod_rewrite.c>
    RewriteEngine on
    <If "%{HTTP_HOST} == 'abc.com'">
        RewriteRule ^/?$ /index.php?pages=abc&file=index [NC,L,QSA]
    </If>
    <If "%{HTTP_HOST} == 'localhost'">
        RewriteRule ^/?$ /index.php?pages=localhost&file=index [NC,L,QSA]
    </If>
</ifModule>

这是另一个例子

RewriteEngine On
    # Conditional Settings
    <If "(%{HTTP_HOST} -strmatch '192.168.254.*')">
        # Localhost/XAMPP
        #RewriteBase /XAMPP-Sites/projectX/public_html/

        # No need for a default domain
    </If>
    <Else>
        # Live
        #RewriteBase /

        # Ensure this is the default domain
        #RewriteCond %{HTTP_HOST} .
        #RewriteCond %{HTTP_HOST} !^www\.projectX\.com [NC]
        #RewriteRule (.*) http://www.projectX.com/$1 [R=301,L]
    </Else>

https://forums.modx.com/thread/92638/one-htaccess-to-rule-them-all