【问题标题】:Cannot redirect to new url using .htaccess无法使用 .htaccess 重定向到新网址
【发布时间】:2017-06-06 22:52:27
【问题描述】:

我有一个 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

【问题讨论】:

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

标签: php html apache .htaccess


【解决方案1】:

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

RewriteEngine On

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    相关资源
    最近更新 更多