apache htaccess重写https request

编程入门 行业动态 更新时间:2024-10-28 09:13:05
apache htaccess重写https request_filename(apache htaccess rewrite https request_filename)

我希望优化一些重写规则,以获得更好的加载性能。 我希望结合规则从HTTP重写到HTTPS,以及处理GET var的文件名重写。

这是正常运行的代码:

RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?var=$1 [L,QSA]

这是我的尝试,它只重定向到%{REQUEST_URI}:

RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ https://%{HTTP_HOST}index.php?var=$1 [R,L,QSA]

I am looking to optimize some rewrite rules for better loading performance. I am hoping to combine rules to rewrite from HTTP to HTTPS as well as handle rewriting of the filename for GET var.

This is the functioning code:

RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?var=$1 [L,QSA]

This was my attempt, which was redirecting to only the %{REQUEST_URI}:

RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ https://%{HTTP_HOST}index.php?var=$1 [R,L,QSA]

最满意答案

AFAIK,如果每个请求都在apache / virtual host配置文件中,则不会为每个请求解析重写规则,而是在服务器启动时对其进行解析和存储。 我不确定.htaccess但是我很确定一旦解析了文件,只要它上面的时间戳发生变化,它就会被重新解析。

在任何情况下,您的组合规则都不起作用,因为重定向到https和通过index.php重写是独立的操作。 您的组合版本只会重写非https的内容。

AFAIK, rewrite rules are not parsed for each request if they are in the apache/virtual host config files, rather they are parsed and stored when the server starts. I'm not certain about .htaccess but I'm pretty sure that once the file has been parsed it is only re-parsed if the timestamp on it changes.

In any case, your combined rule won't work because the redirect to https and the rewrite through index.php are independent actions. Your combined version will only rewrite things that are NOT https.

更多推荐

本文发布于:2023-08-06 10:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   htaccess   apache   https   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!