apache .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
Please help me. This problem has bothered me for 3 days. Thank you very much
I try to convert it into the following
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
Authorization cannot be obtained correctly on nginx,Can cause CORS problems
I think it’s because this sentence hasn’t been converted successfully
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
because I don’t know how to convert it
Please help me
I expect to get the converted nginx htaccess
2
Answers
This is the answer
The
.htaccess
you’re seeking to convert is quite standard "front controller" pattern. What it does is, for any URI, it will attempt to:index
directives or further rewrites)index.php
The de-facto standard NGINX snippet that does the same, utilizes
try_files
directive.You’ll find this used for virtually all PHP-based CMS configs for NGINX:
The
try_files
directive, similar toif
when being checked for file existence, has its performance pitfalls, so in fact, you may want to do as the article says is route unconditionally all request via PHP-FPM by default, then some (e.g. static assets) served by NGINX directly. Example bare-bones config for WordPress which illustrates the idea:In this case
/wp-content/
is allocated as an empty location in order to ensure NGINX does not pass requests to files in it via PHP-FPM. It will serve everything directly for static files.Thus the URL rewriting is actually eliminated, and all the performance penalty that comes with it is negated.