Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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
Php 在编写.htaccess时遇到了一些问题_Php_Html_.htaccess - Fatal编程技术网

Php 在编写.htaccess时遇到了一些问题

Php 在编写.htaccess时遇到了一些问题,php,html,.htaccess,Php,Html,.htaccess,我有一个页面,我正在尝试为它编写一个正确的.htaccess文件 目前我有以下代码: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 所以这一切都很好,但我希望它吐出的网址与'www'在前面 我已经试过了: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https:

我有一个页面,我正在尝试为它编写一个正确的.htaccess文件

目前我有以下代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
所以这一切都很好,但我希望它吐出的网址与'www'在前面

我已经试过了:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但它显然不是那样工作的

如果你能帮我,我会很高兴的,
非常感谢。

你可以试试这样的东西

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
还是这个

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
可能重复的