<分区>
<分区>
如何判断 http://ttt.com或 http://www.ttt.com被用户使用,重定向到https://www.ttt.com ?
httpd.conf:
<VirtualHost *:80>
ServerName www.ttt.com
ServerAlias ttt.com
DocumentRoot /home/www/html/ttt/public
<Directory /home/www/html/ttt/public>
#Options ExecCGI
#AddDefaultCharset utf-8
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess :
RewriteEngine On
############################################
## always send 404 on missing files in these folders
#RewriteCond %{REQUEST_URI} !^/(files)/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
最佳答案
在主目录 .htaccess 文件中尝试以下代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
关于Apache - 如何将 http 请求仅转换为 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37032053/
相关文章:
java - 如何将应用程序从 Tomcat8 映射到 JBoss Web 服务器中的 Apache?
php - ISPConfig 3,忍者设置我的 open_basedir
python - Snow Leopard 上的 mod_wsgi python 版本不匹配
javascript - $locationProvider html5mode 导致刷新时出现 "cannot GET"错误 - AngularJS Node 应用程序
.htaccess - Joomla 2.5 SEO,带有 "/"的 SEF URL 得到 404 错误
.htaccess - 我应该为 htaccess 使用重定向 301
php - Doctrine ZFA\排除字段显示在 IIS 上的表单上