Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess非www到非www SSL和www到www SSL_.htaccess_Ssl_No Www - Fatal编程技术网

.htaccess非www到非www SSL和www到www SSL

.htaccess非www到非www SSL和www到www SSL,.htaccess,ssl,no-www,.htaccess,Ssl,No Www,我搜索了每个地方,尝试了各种.htaccess配置,但没有找到答案 由于只能访问.htaccess文件,我想: 直接非www到非www SSL 示例:http://example.com->https://example.com 及 直接www到www-SSL 示例:http://www.example.com->https://www.example.com 大多数示例显示将所有请求强制作为非www或www传输到SSL。我想要两者 htaccess <IfModule mod_heade

我搜索了每个地方,尝试了各种
.htaccess
配置,但没有找到答案

由于只能访问
.htaccess
文件,我想:

直接非www到非www SSL 示例:
http://example.com
->
https://example.com

直接www到www-SSL 示例:
http://www.example.com
->
https://www.example.com

大多数示例显示将所有请求强制作为非www或www传输到SSL。我想要两者

htaccess

<IfModule mod_headers.c>
  Header append Vary: User-Agent
  Header append Vary: Accept-Encoding
</IfModule>

AddDefaultCharset utf-8
AddType image/svg+xml svg

RewriteEngine On

RewriteRule ^sitemap\.xml$ /sitemap.php [L]

# Exception - Reached the document root then stop
# (Prevents rewrite loop if index.php is missing - 404 instead)
RewriteRule ^index\.php$ - [L]

# Exception - Any request for a valid file stop here
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# If already requesting "index.php" then step up a directory
RewriteRule ^(.*/)?[^/]+/index\.php$ /$1index.php [L]

# Otherwise try "index.php" in the current path segment
RewriteRule ^(.*/)?[^/]*$ /$1index.php [L]

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilter DEFLATE .shtml
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
AddType image/x-icon .ico
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/ico "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/svg "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>

标题:用户代理
头附加变量:接受编码
AddDefaultCharset utf-8
AddType图像/svg+XMLSVG
重新启动发动机
重写规则^sitemap\.xml$/sitemap.php[L]
#异常-到达文档根目录,然后停止
#(如果index.php丢失,则防止重写循环-改为404)
重写规则^index\.php$-[L]
#异常-对有效文件的任何请求均在此停止
RewriteCond%{REQUEST_FILENAME}-f
重写规则^-[L]
#如果已经在请求“index.php”,那么升级一个目录
重写规则^(.*/)?[^/]+/index\.php$/$1index.php[L]
#否则,请在当前路径段中尝试“index.php”
重写规则^(.*/)?[^/]*$/$1index.php[L]
SetOutputFilter放气
SetEnvIfNoCase请求\u URI“\(?:gif | jpe?g | png)$”无gzip
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/x-javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilter DEFLATE.shtml
过期于
AddType image/x-icon.ico
过期按类型图像/x图标“访问加1年”
过期按类型映像/ico“访问加1年”
过期按类型映像/jpg“访问加1年”
过期按类型图像/jpeg“访问加1年”
ExpiresByType image/gif“访问加1年”
过期按类型图像/png“访问加1年”
ExpiresByType图像/svg“访问加1年”
ExpiresByType图像/svg+xml“访问加1年”
ExpiresByType文本/css“访问加1个月”
过期按类型应用程序/pdf“访问加1个月”
ExpiresByType text/x-javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
过期按类型图像/x图标“访问加1年”
ExpiresDefault“访问加2天”
您可以使用:

RewriteEngine on 
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

然后只需强制
HTTPs
…看看
RedirectPermanent
(和其他重定向指令),对于这样的简单需求,它们已经足够了,您不需要
mod_rewrite
。这样做似乎会创建无限重定向。添加了完整的htaccess文件以供参考。