.htaccess重定向到`www.www.example.com`

时间:2018-04-16 18:28:46

标签: .htaccess laravel-5

我正在使用DISTINcT ON构建网站,并且我的Laravel5文件重定向到.htaccess时出现问题。我试图强制从https://www.www.example.com重定向到http,现在我在网址中遇到重复的https

通过www.(不使用https://example.com)访问该网站的工作正常。

这是我的www文件内容:

.htaccess

任何人都可以提供有关需要更改的建议,以强制重定向到<IfModule mod_rewrite.c> DirectoryIndex public/index.php public/index.html <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{SERVER_PORT} 80 RewriteCond %{HTTP_HOST} ^(www\.)?example\.com RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ /public/index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule> ,同时允许以下网址访问该网站并重定向到https

  • https://www.example.com
  • www.example.com
  • https://example.com
  • https://www.example.com
  • http://www.example.com

1 个答案:

答案 0 :(得分:1)

有这样的话:

<IfModule mod_rewrite.c>
    DirectoryIndex index.php index.html

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # add www with http -> https
    RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    RewriteCond %{HTTPS} !on
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /public/index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

确保使用新的浏览器进行测试以避免旧缓存。