【发布时间】:2019-11-25 13:08:30
【问题描述】:
基本上,由于请求,我无法使用 php 返回 css、js、图像或字体,因为浏览器将其作为 html 文件读取,因此,我试图在.htaccess 来重定向请求,所以我不必在 php 中处理那些文件。
此外,无论如何我都需要强制使用 https。
我使用的是 Apache/2.2.31,所以我不能使用语法<If "true"> </If>。
可选的是处理请求头,所以浏览器可以读取文件的真实类型,但我不知道如何。
我是 .htaccess 的新手,我很确定这应该很容易。
代码如下:
RewriteEngine On
#this is just to forcing https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
# if css, js, html, images and fonts, do not redirect anything
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png|woff?2|otf|html)$ [NC]
RewriteRule # I don't know how to do anything
# else if the folder is “admin”, don’t do anything
RewriteCond %{THE_REQUEST} /admin/([^\s?]*) [NC]
RewriteRule # I don't know how to do anything
# else if the file is php or a folder, redirect to public folder
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
任何帮助将不胜感激,谢谢。
【问题讨论】:
-
可以添加你想要实现的重定向作为例子吗?
-
当然你可以通过php返回任何你想要的内容,只是html,如果你指定了正确的mime类型 ...
标签: php .htaccess header-files