【发布时间】:2019-04-14 16:15:53
【问题描述】:
我使用 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/
它确实有效——所以我在这里做错了吗?
【问题讨论】:
标签: php apache .htaccess routes