[英]htaccess rewrite to https except for few pages and files
我使用htaccess文件重写一些url,还将http请求重写为https:
# No Caching for page files
<filesMatch "\.(html|htm|js|css|php)$">
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
</filesMatch>
# Error pages
ErrorDocument 404 https://%{HTTP_HOST}/#/404
ErrorDocument 500 https://%{HTTP_HOST}/#/500
RewriteEngine On
# Rewrite www to non
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R,L]
# Rewrite http to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^\/tvgids\/
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Ignore conditions for files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /
# Rewrite /api to api.php
RewriteRule ^api/(.+)$ api/api.php [QSA,L]
# Rewrite /tvgids to guide/index.php
RewriteRule ^tvgids/(.+)$ guide/index.php [QSA,L]
# Rewrite /tv to m3u/index.php
RewriteRule ^tv/(.+)$ m3u/index.php [QSA,L]
# Rewrite /get to get/index.php
RewriteRule ^get/(.+)$ get/index.php
# Rewrite /downloads to downloads.php
# RewriteRule ^download/(.+)$ download/download.php [QSA,L]
但是/ tvgids的重写条件不起作用:
RewriteCond %{REQUEST_URI} !^\/tvgids\/
相反,如果我尝试输入/ tvgids / abc,则会收到404。
除了少数页面外,我需要所有页面重写为https,因为它们在不支持https的android应用中使用。
谁能帮我这个忙-现在我必须为所有页面禁用ssl,因为否则什么也没有用。 我看不到我在做什么错,条件是否正确?
我也试过这个:
RewriteCond %{REQUEST_URI} !(tvgids\/.*|tv\/.*|get\/.*|\.png|\.jpg|\.jpeg|\.ico)$ [NC]
这也将我重定向到https ..但如果在这里进行测试: https : //htaccess.madewithlove.be/
它确实有效-所以我在这里做错了吗?
我实际上可以使用以下代码:
# Rewrite http to https
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !(/tvgids/|/tv/) [NC]
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{THE_REQUEST} !/tvgids/ [NC]
设置一个条件,当请求tvgids /时,将不会重定向到https。 而且我不需要排除图像文件类型,因为我已经设置了排除文件夹和文件的条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.