use*_*856 21 .htaccess redirect front-controller
我有一个.htaccess文件,其中包含以下内容:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
有了这个,我希望将所有请求重定向到文件,entryPoint.php以便它可以检查它们:
如果是.png,那么这是一个"安全"的电话.
在图像的情况下,我曾经输出标题file_get_contents()及其内容.我发现它比直接读取要慢一些.
entryPoint.php如果有图片参考,如何防止这个.htaccess调用?
我已经拥有的代码的额外反馈非常感谢!
und*_*one 43
据我所知,你想处理所有非图像扔你的PHP文件.对?
如果是这样,那么这就是你需要的:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule (.*) entryPoint.php [QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
请务必添加以删除您想要的任何图片扩展名!如果我误解了,请告诉我更正我的答案!
你可以使用这样的东西来停止重写图像
RewriteRule \.(jpg|png)$ - [L]
Run Code Online (Sandbox Code Playgroud)
这条规则说'如果请求的文件以句点结尾,后跟"jpg"或"png",则不要重写它.
该$字符只标记"字符串/文件名的结尾",-表示"如果此规则匹配则不重写URL",并且"如果匹配[L]则不再处理任何规则".
我要补充的是处理这种事情的通常的方法是只适用的毯子声明"如果这个文件存在只是提供服务的文件了,直接,但任何一个不存在得到由PHP处理." 这种规则看起来像这样:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
这表示"如果请求不是针对存在的文件或目录,请将请求传递给index.php,并将原始路径作为名为'request'的查询字符串参数传递,将任何其他查询字符串参数附加到新请求. "
RewriteCond %{REQUEST_FILENAME} !\.(png|jpg|gif)$
Run Code Online (Sandbox Code Playgroud)
把这条线放在你的前面 RewriteRule
| 归档时间: |
|
| 查看次数: |
38189 次 |
| 最近记录: |