首页 > 解决方案 > htaccess url 重写和 https

问题描述

我有一个以前在服务器上设置为 http 地址的网站。现在我更改了服务器,网站应该是 https。

所以我决定在.htaccess文件中进行更改,但它不起作用(500错误,网页没有出现)

这是我的 htaccess 文件内容:

Options +FollowSymLinks 
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
    
#allow to add "www." if missing
    
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) https://www.mywebsite.com/$1 [L,R,NE]

php_flag "allow_url_fopen" "On"

# URL rewrites

   RewriteRule ^home$  /index.php?content=home&lang=en [L]
   RewriteRule ^home-notice-1$  /index.php?content=home&val=1&lang=en [L]
   RewriteRule ^home-notice-2$  /index.php?content=home&val=2&lang=en [L]
   RewriteRule ^home-notice-3$  /index.php?content=home&val=3&lang=en [L]
   RewriteRule ^featured-news$  /index.php?content=news&mode=featured&lang=en [L]            
   etc...

有人可以告诉我有什么问题吗?基本上,与以前相比,我所做的只是添加了“RewriteCond %{HTTPS} off”并将“RewriteRule ^/?(. ) http:...”更改为“RewriteRule ^/?(. ) https:... ”。当然,“mywebsite.com”是我网站真实名称的占位符,我显然输入正确。

从 ftp 客户端的角度来看,这似乎是结构:

从根目录到 index.php:

->rb4t7.ftp.mywebhost.com
    ->sites (folder)
        ->mywebsite.com (folder)
             .htaccess (file)
             index.php (file)
             ...

谢谢

标签: .htaccesshttpsurl-rewriting

解决方案


好的,我所要做的就是复制/粘贴“#URL Rewrites”下面的部分。显然,其他一切都在搞乱系统。https 以某种方式在本地得到了照顾。谢谢


推荐阅读