使用mod_rewrite将“https://”请求转换为“http://”

时间:2015-01-08 01:42:49

标签: apache .htaccess mod-rewrite

我正在为https请求获取404,因为我正在修改使用https的现有项目。我没有ssl,我也不需要https。我更改了所有的base_url并链接到正常的http.For将所有https转换为http我将我的.htaccess更改为此 -

Options +FollowSymlinks
Options -Indexes

### Url rewrite ###

RewriteOptions inherit
RewriteEngine on
RewriteOptions MaxRedirects=5

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|auth|register|secure|js|css|img)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]

#Other redirects
RewriteRule \.json$ notfound.php [L,QSA]
RewriteRule ^viz/apps/.+\.js$ notfound.php [L,QSA]
RewriteRule ^viz/index.php - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^viz/(.*)$ viz/index.php?/$1 [L,QSA]

ErrorDocument 404 notfound

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

但它不起作用。如何将image,css,js的所有https请求转换为普通的http请求。请帮忙。提前谢谢。

针对https的Previous .htaccess就像这样 -

Options +FollowSymlinks
Options -Indexes

### Url rewrite ###

RewriteOptions inherit
DirectorySlash Off
RewriteEngine on
RewriteOptions MaxRedirects=5

#Everything to HTTPS
RewriteCond %{HTTPS} !^on$
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond %{QUERY_STRING} !^/insecure/.*
RewriteCond %{REQUEST_URI} !^/viz/insecure/.*
#RewriteCond %{REQUEST_URI} !^/viz/index.php/insecure/.*
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Other redirects
RewriteRule \.json$ notfound.php [L,QSA]
RewriteRule ^viz/apps/.+\.js$ notfound.php [L,QSA]
RewriteRule ^viz/index.php - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^viz/(.*)$ viz/index.php?/$1 [L,QSA]

ErrorDocument 404 notfound
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

1 个答案:

答案 0 :(得分:0)

如果您的服务器无法通过https建立连接,则无法在客户端通过https请求页面时重定向客户端。它是需要发送此标头的服务器,但由于没有建立连接,因此它也无法发送标头。

即使您的服务器能够提供https服务,添加https-to-http规则也无法解决您的问题。您最终会通过Apache将https重定向到http,并通过您的应用程序从http重定向到https。您需要修复应用程序才能解决此问题。