Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
在.htaccess中强制使用WWW和HTTPS(SSL)——需要帮助_.htaccess_Ssl - Fatal编程技术网

在.htaccess中强制使用WWW和HTTPS(SSL)——需要帮助

在.htaccess中强制使用WWW和HTTPS(SSL)——需要帮助,.htaccess,ssl,.htaccess,Ssl,我发现有上千个其他的主题在寻求帮助,但由于某些原因,它们的解决方案似乎都不起作用 我几天前刚为我的域名购买了SSL,因为我在我的网站上接受信用卡/支票卡,我希望我的客户感到安全 无论如何,这就是我的.htaccess文件目前的样子: php_flag display_startup_errors off php_flag display_errors off Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} !

我发现有上千个其他的主题在寻求帮助,但由于某些原因,它们的解决方案似乎都不起作用

我几天前刚为我的域名购买了SSL,因为我在我的网站上接受信用卡/支票卡,我希望我的客户感到安全

无论如何,这就是我的.htaccess文件目前的样子:

php_flag display_startup_errors off
php_flag display_errors off

Options +FollowSymLinks
RewriteEngine On

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

RewriteRule ^buy-wow-accounts index.php [NC]
RewriteRule ^sell-wow-accounts sell.php [NC]
RewriteRule ^about-khaccounts about.php [NC]
RewriteRule ^buy-sell-wow-accounts-faq faq.php [NC]
RewriteRule ^khaccounts-feedback feedback.php [NC]
RewriteRule ^payment-plan payment-plan.php [NC]
RewriteRule ^customer-login customer-login.php [NC]
RewriteRule ^customer-center customer-center.php [NC]
RewriteRule ^privacy-policy privacy.php [NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts/page-([0-9]+) listing.php?pageid=$1 [L,NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts listing.php [L,NC]
RewriteRule ^world-of-warcraft-wow-acc/([^/]*)\.html$ account.php?acc=$1 [NC]
我想做的是强制WWW,如果它不在URL中,并确保HTTPS(SSL)也是强制的。我的网站有很多链接,其中大部分都是像“www.khaccounts.net”这样的链接http://khaccounts.net,以及“khaccounts.net”

我想确保这些不同的旧链接中的每一个都将被强制使用WWW和HTTPS。换句话说,我希望人们有URL-'https://www.khaccounts.net“不管他们用什么URL访问我的网站


谢谢

在您的www规则之后添加:

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

另外,将您的www规则更改为https://,这样就不会有两个重定向。

看起来您正在将所有URL重写到根目录。你为什么不试试:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]

尝试替换以下行:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
为此:

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.khaccounts\.net$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]

这可以在命中KhaAccounts.net时显示正确的URL,但仍会引发重定向循环

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]

这似乎满足了我的需要,但问题是,它在URL中的所有内容都是它缺少请求的URL。这很奇怪,$1用于捕获请求的URL并将其传递给新的URL。。。嗯…是的,所有显示的是--https:\\www.--就是这样。我把\.khaccounts\.net$1作为重写规则,它给了我正确的URL,但让我进入了重定向循环。Yazmat还有其他想法吗?我的服务器上是否应该安装一些我可能缺少的东西?我启用了mod_rewrite,SSL证书工作得很好。我不知道为什么,请尝试启用rewrite日志,看看在执行请求时实际发生了什么,这可能会让您对这个问题有更好的想法。这不起作用。当我输入'khaccounts.net'时,它在URL中显示',并表示该页面有一个重定向循环。