Php htaccess仅启用浏览器缓存子域站点

Php htaccess仅启用浏览器缓存子域站点,php,apache,.htaccess,caching,Php,Apache,.htaccess,Caching,我在根.htaccess文件中添加了浏览器缓存,该站点在多个域/子域上工作,例如:www.domain.com,mt.domain.com,rt.domain.com,所有站点都使用相同的代码。。我使用了Codeigniter框架 现在缓存在所有域/子域上启用,是否可以添加特定的域/子域进行缓存 .htaccess文件 <IfModule mod_rewrite.c> RewriteEngine On ########### TODO: deploying on su

我在根
.htaccess
文件中添加了浏览器缓存,该站点在多个域/子域上工作,例如:
www.domain.com
mt.domain.com
rt.domain.com
,所有站点都使用相同的代码。。我使用了
Codeigniter
框架

现在
缓存
在所有域/子域上启用,是否可以添加特定的域/子域进行缓存

.htaccess
文件

<IfModule mod_rewrite.c>
    RewriteEngine On
    ########### TODO: deploying on subdir must rewrite this
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    Options -Indexes

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 seconds"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
    SetOutputFilter DEFLATE
</FilesMatch>
<IfModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

重新启动发动机
###########TODO:在子目录上部署必须重写此
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
选项-索引
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php
##过期缓存##
过期于
过期按类型映像/jpg“访问1年”
过期按类型图像/jpeg“访问1年”
ExpiresByType image/gif“访问1年”
过期按类型图像/png“访问1年”
ExpiresByType文本/css“访问1个月”
ExpiresByType文本/html“访问1秒”
过期按类型应用程序/pdf“访问1个月”
ExpiresByType文本/x-javascript“访问1个月”
过期按类型应用程序/x-shockwave-flash“访问1个月”
过期按类型图像/x图标“访问1年”
ExpiresDefault“访问1个月”
##过期缓存##
SetOutputFilter放气
mod_gzip_on Yes
是的
mod_gzip_item_include file\(html?| txt | css | js | php | pl)$
mod_gzip_item_包含处理程序^cgi脚本$
mod_gzip_项目包括mime^text/*
mod_gzip_item_包括mime^application/x-javascript*
mod_gzip_项_排除mime^image/*
mod_gzip_item_排除rspheader^内容编码:.*gzip*

感谢您的帮助

这在使用环境变量的Apache 2.2中实际上是可能的。不幸的是,它不适用于您正在使用的
mod_expires
。我们将使用
mod_headers
来代替,这没有太大区别

它看起来有点复杂,但这是因为我们不能逻辑地组合(和/或)环境变量

# Sets an env. var. if the subdomain matches, and initializes the other env. var.
SetEnvIfNoCase HOST ^subdomain\.example\.com$ do_cache=1 is_static_file=0

# changes the value of other env. var. if extension matches (here: PNG or GIF)
SetEnvIfNoCase Request_URI .*\.(png|gif)$ is_static_file=1

# resets the first env. var. to 0 if the type didn't match
SetEnvIf is_static_file 0 do_cache=0

# now you can set arbitrary headers based on whether both conditions were met.
# (we're using nonsense "X-Success" headers here, for testing)
Header set X-Success "yes" env=do_cache
Header set X-Success "no" env=!do_cache
准备上线时,请将
X-Success
标题行替换为以下内容:

Header set Cache-Control "max-age=290304000, public" env=do_cache
如果通过子域调用静态文件,这将激活静态文件的缓存


您可以根据需要添加任意数量的
标题
或此类型的其他指令。您必须只确保该指令接受附录(
标题
有,
过期类型
没有)。

您是否有权访问
httpd.conf
,更具体地说是您的
虚拟主机
,或者您拥有的唯一选项是
htaccess
?您的apache版本是什么,2.2+还是2.4+?我可以访问
httpd.conf
,apache正在使用
2.2
版本感谢您的回复,我创建了一个虚拟主机
通配符子域,因为子域站点是不固定的,这些站点是从站点管理器发布的。。我想在所有子域站点上应用缓存,并从缓存中跳过站点管理器(domain.com),但问题是主站点和子域站点代码相同。。我们能为子域(*.domains.com)使用另一个
.htaccess
吗?运气好的话。谢谢你的回答,我会试试的。。我们将如何在
标题集中设置
内容类型
,因为我想即时终止内容类型(
text/html,application/json/text/json
),只需通过扩展名即可。对于静态文件,这应该不是问题。唯一不起作用的情况是编写自己的头的动态(PHP)文件。但它们也应该能够控制自己的缓存。