简体   繁体   English

不使用.htaccess自动从http重定向到https

[英]Not redirecting from http to https automatically using .htaccess

Trying to redirect my website from http to https, but its not working... website opens on both http and https. 尝试将我的网站从http重定向到https,但它无效......网站在http和https上打开。

This is the code section presently i used in my htaccess file, but this code not auto redirecting the website with https, and making the website open with both http and https. 这是我目前在我的htaccess文件中使用的代码部分,但是此代码不会使用https自动重定向网站,并使用http和https打开网站。 which is confusing so much. 这让人很困惑。

    ------------------------------------------------

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule . /index.php [L]

    </IfModule>

    # END WordPress
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-SSL} !on
    RewriteCond %{HTTP_HOST} ^www\.surffares\.com$
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^/?$ "https\:\/\/www\.surffares\.com\/" [R=301,L]

------------------------------------------------------------------------

but this code is not working ... 但是这段代码不起作用......

This is code godaddy suggested to use in htaccess for auto redirect, but this code only loading the front page, auto redirecting the front page only but no other page is opening, when i click any other page, it shows me a error not found. 这是代码godaddy建议在htaccess中使用自动重定向,但此代码只加载首页,自动重定向首页但没有其他页面打开,当我点击任何其他页面时,它显示我找不到错误。

---------------------------------------------------------------------
    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
    RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

--------------------------------------------------------------------

Godaddy Customer support told you need to pull inner pages in .htaccess. Godaddy客户支持告诉您需要在.htaccess中提取内页。

How i can auto redirect my website from http to https and also pull all the inner pages of the website. 我如何自动将我的网站从http重定向到https,并拉出网站的所有内页。

NOTE: my website is in php mvc laravel 注意:我的网站是在php mvc laravel

I've quickly built a configuration to test this scenario. 我已经快速构建了一个配置来测试这个场景。 In Apache VirtualHost you need to make sure that htaccess-files are respected by apache with AllowOverride . 在Apache VirtualHost中,您需要确保apache使用AllowOverride遵守htaccess文件。

Here is the configuration within the VirtualHost: 以下是VirtualHost中的配置:

    <VirtualHost *:80>

     ServerName test.com
     DocumentRoot /var/www

    <Directory "/var/www>
      Require all granted
      AllowOverride all
    </Directory

  </VirtualHost>

Then, in /var/www/.htaccess, define the following: 然后,在/var/www/.htaccess中,定义以下内容:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

Hope that helps. 希望有所帮助。

Jo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM