【问题标题】:Use .htaccess to change where a domain points使用 .htaccess 更改域指向的位置
【发布时间】:2015-02-24 17:30:39
【问题描述】:

我有一个 .htaccess 文件,将我的 .com 域更改为 .co.uk,我的 .co.uk 有 ssl 证书,但 .com 没有。

当我输入时: http:// 或 万维网。要么 例子.com

一切正常,但如果它的http://example.com 不会重写为https://www.example.co.uk

我将如何更改它以使其在 .htaccess 中起作用?

我目前的规则是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?user=$1

ErrorDocument 404 /404.html

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

非常感谢

【问题讨论】:

  • 你目前的规则是什么?
  • 刚刚添加它们,抱歉应该把它们放在首位

标签: .htaccess


【解决方案1】:

您的规则有一些问题。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?user=$1

需要在最后,否则会同时重定向路由。

然后改变:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

到:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$ [NC]
RewriteRule ^ https://www.example.co.uk%{REQUEST_URI} [L,R=301]

【讨论】:

    猜你喜欢
    • 2017-04-15
    • 1970-01-01
    • 2011-10-13
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 2014-02-09
    • 1970-01-01
    相关资源
    最近更新 更多