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



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

<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>

你的意思是这样的吗

<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

最新更新