Php 无法使用.htaccess重定向到新url

Php 无法使用.htaccess重定向到新url,php,html,apache,.htaccess,Php,Html,Apache,.htaccess,我有一个html网页,在该网站的徽标上,我将我的徽标URL写为 example.com现在,我想将所有请求重定向到example.com转到http://www.example.com 这是迄今为止我的.htaccess: ErrorDocument 404 http://www.example.com/404.html Redirect /index.html http://www.example.com RewriteCond %{HTTP_HOST} ^example.com$ R

我有一个html网页,在该网站的徽标上,我将我的徽标URL写为

example.com
现在,我想将所有请求重定向到
example.com
转到
http://www.example.com

这是迄今为止我的
.htaccess

ErrorDocument 404 http://www.example.com/404.html 
 Redirect /index.html http://www.example.com

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

example.com
未被重定向到
http://www.example.com

您需要在
.htaccess
中使用以下内容:

RewriteEngine On

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

请确保在测试之前清除缓存。

我认为您需要在重写规则
^(.*)$
中添加一个
^
,否则您不知道匹配的是什么。