我想知道正确的语法来检查主页(例如abc.com
或localhost
),以便为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>
答案 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