2015-05-25 24 views
21

Tôi có trang web đang hoạt động trên đó. khi tôi mở bất kỳ trang nào với giao thức http: //, mọi thứ đều được tải chính xác, nhưng khi tôi cố gắng tải trang có giao thức https, trang được tải nhưng không có tệp css và javascript.
Bảng điều khiển hiển thị các lỗi sau.Trang nội dung hỗn hợp: đã yêu cầu lỗi biểu định kiểu không an toàn

Content Mixed: Trang tại 'https://www.example.com/index.php?main_page=login' đã được nạp qua HTTPS, nhưng yêu cầu một kiểu không an toàn 'http://www.example.com/site_map.html'. Yêu cầu này đã bị chặn ; nội dung phải được phân phối qua HTTPS.

Tôi nhận thấy rằng sự cố là trình duyệt không thể tải bất kỳ tệp css nào khi được yêu cầu bởi giao thức https.
Vấn đề là với tập tin htaccess, bởi vì khi tôi gỡ bỏ nó, các tập tin css nạp một cách chính xác.

Trang và css file nạp vào trình duyệt với https trong url của họ như thế này

<link rel="stylesheet" type="text/css" href="https://www.example.com/includes/templates/classic/css/style1.css"> 
<link rel="stylesheet" type="text/css" href="https://www.example.com/includes/templates/classic/css/style2.css"> 

khi trình duyệt cố gắng để tải các tập tin css, nó được chuyển hướng đến

http://www.example.com/site_map.html 

thế nào tôi có thể làm cho htaccess cho phép https để mở các tập tin css và js trong một thư mục cụ thể?

Cảm ơn

CẬP NHẬT Nội dung file .htaccess

RewriteEngine On 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule (.*) http://www.example.com/$1 
############################################################################### 
# Common directives 
############################################################################### 
# NOTE: Replace /shop/ with the relative web path of your catalog in the "Rewrite Base" line below: 

Options +FollowSymLinks 
RewriteEngine on 

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L] 

#RewriteBase/

############################################################################### 
# Start Ultimate SEO URLs 
############################################################################### 

# Original (unchanged) URL formats 
RewriteRule ^(.*)-p-([0-9]+)(.*)$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L] 
RewriteRule ^(.*)-c-(.*)-p(.*)\.html$ /index.php?main_page=$4&cPath=$2&sort=$5&page=$3 
RewriteRule ^(.*)-c-([0-9_]+)(.*)$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L] 
RewriteRule ^(.*)-ez-(.*).html$ index.php?main_page=page&id=$2 [L] 

# All other pages 
# Don't rewrite real files or directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index\.php?main_page=$1&%{QUERY_STRING} [L] 


# Block out any script trying to base64_encode data within the URL. 
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] 
# Block out any script that includes a <script> tag in URL. 
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR] 
# Block out any script trying to set a PHP GLOBALS variable via URL. 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
# Block out any script trying to modify a _REQUEST variable via URL. 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule index.html$ index.php [QSA] 


# 480 weeks 
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> 
Header set Cache-Control "max-age=290304000, public" 
</FilesMatch> 

# 2 DAYS 
<FilesMatch "\.(xml|txt)$"> 
Header set Cache-Control "max-age=172800, public, must-revalidate" 
</FilesMatch> 

# 2 HOURS 
<FilesMatch "\.(html|htm)$"> 
Header set Cache-Control "max-age=7200, must-revalidate" 
</FilesMatch> 
# compress text, html, javascript, css, xml: 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/x-javascript 

RewriteEngine on 
RewriteBase/

ErrorDocument 404 /index.php 
RewriteRule index.html$ index.php [QSA] 
+0

Bạn có thể đăng nội dung của '.htaccess' không? – joews

+0

Tôi đã cập nhật câu hỏi – developer

Trả lời

3

Dưới đây là vấn đề của bạn:

RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule (.*) http://www.example.com/$1 

Bạn không cho phép yêu cầu SSL (443 số cổng được sử dụng cho các yêu cầu HTTPS). Hãy thử xóa những dòng này.

4

lẽ Hầu hết bên trong mã html của bạn, bạn có cái gì đó như

<link href="http://someSite.com/css/someStyle.css" rel="stylesheet" type="text/css" /> 

bạn nên thay đổi này để

<link href="https://someSite.com/css/someStyle.css" rel="stylesheet" type="text/css" /> 

cũng là trang bạn đang đề cập đến là .html không css, nhưng tôi đoán đó là lỗi đánh máy ...

+0

Khi trang được tải bằng https và các tệp url css cũng được sử dụng https.khi trình duyệt mở nó, phản hồi của máy chủ với trang chuyển hướng là 'http://www.example.com/site_map.html' trong trường hợp của tôi – developer

+1

tôi đã có http trong tệp css của mình. thay đổi để htpps cũng làm việc. cảm ơn! – Jona

+0

@loannis Loukeris, 'http' và 'hhtps' phải là động. Người dùng có thể duyệt bằng bất kỳ ứng dụng nào. Cảm ơn –

11

Nếu bạn có thể phân phát CSS qua HTTPS, giải pháp tốt nhất là use // as the scheme cho URL nội dung.

Điều đó có nghĩa "sử dụng các chương trình tương tự (đôi khi được gọi giao thức) như tài liệu gốc", ví dụ: sử dụng https nếu trang sử dụng https. Ví dụ:

<link rel="stylesheet" href="//mysite.com/styles.css"> 
<script src="//mysite.com/app.js"></script> 
+1

Bạn đã bỏ lỡ tên miền của URL – andale

+0

vui lòng xem nội dung cập nhật về câu hỏi của tôi – developer

+0

@andale Bạn nói đúng, cảm ơn. – joews

1

Tôi đã sử dụng plugin của cloudflare như được mô tả trong hướng dẫn here.

Các vấn đề liên quan