What does this Rewrite rule mean?

随声附和 提交于 2020-01-12 19:05:45

问题


Im installing phpancake, there is a folder there shema like this

application/
install/
library/
public/
sql_schema/
install.html
install.php

What does this rule mean?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /vote/public/index.php [NC,L]

回答1:


The rewrite has two parts. The first one specifies that if the requested filename is a regular file with a size greater than 0 (-s), a symbolic link (-l) or a directory (-d), rewrite to nowhere, eg. take no action. [NC,L] means that the rule is non case sensitive and the last rule that these conditions match.

All other requests are forwarded to /vote/public/index.php.

The purpose of this rewrite is that an actual, existing file can be fetched from the server without interference. Without the first rule, every file request (css and js files, images etc) would go to index.php which would mess things up pretty badly.

Usually this is written in one declaration, though. You can negate the conditions, and then the [OR] statemens can be taken out also:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /vote/public/index.php [NC,L]

This is equivalent to the original statement.




回答2:


Those are mainly standard rewrites which check if the requested file (or directory or symbolic link) exists on disk, in which case the file/directory/etc. should be used.

All other matches should go to /votes/public/index.php




回答3:


The first rule will pass through all requests that can be mapped to a regular file with a size greater than zero (-s), a symbolic link (-l) or a directory (-d). Every other request is fetched by the second rule and rewritten to /vote/public/index.php.



来源:https://stackoverflow.com/questions/2074476/what-does-this-rewrite-rule-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!