我希望优化一些重写规则,以获得更好的加载性能。 我希望结合规则从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.
更多推荐
发布评论