[英]Explain this mod_rewrite rule
Can anyone explain what this mod_rewrite rule is doing? 谁能解释一下这个mod_rewrite规则在做什么?
I'm trying to comment the file, but the code seems to state the opposite of what I think it's doing 我正试图评论该文件,但代码似乎与我认为它正在做的相反
# Enable rewriting of URLs
RewriteEngine on
# Allow specified file types to be accessed
# Thing to test = URL
# Condition = not starting with
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
# RewriteRule will only be performed if the preceeding RewriteCond is fulfilled
# Remove index.php from all URLs
# Pattern = anything (0 or more of any character)
# Substitution = index.php + the rest of the URL
RewriteRule ^(.*)$ /index.php/$1 [L]
The browser sends a request to the server (Apache, since you're using mod_rewrite): 浏览器向服务器发送请求(Apache,因为您正在使用mod_rewrite):
GET profile/edit 获取个人资料/编辑
Apache accepts this request and sees in its configuration files that you've configured it to pass all requests through mod_rewrite. Apache接受此请求,并在其配置文件中看到您已将其配置为通过mod_rewrite传递所有请求。 So, it sends the string 'profile/edit' to mod_rewrite.
因此,它将字符串'profile / edit'发送到mod_rewrite。 Mod_rewrite then applies the rules you specified to it, which then transforms the request (in the way I explained in my previous post) to 'index.php/profile/edit'.
然后,Mod_rewrite将您指定的规则应用于它,然后将请求(以我在上一篇文章中解释的方式)转换为'index.php / profile / edit'。 After mod_rewrite is done, Apache continues processing the request, and sees 'oh, this guy is requesting the file index.php'.
mod_rewrite完成后,Apache继续处理请求,并看到'哦,这家伙正在请求文件index.php'。 So it calls the php interpreter which then parses and executes index.php - and gets '/profile/edit' as arguments.
所以它调用php解释器然后解析并执行index.php - 并将'/ profile / edit'作为参数。 The php code (CI in your case) parses these arguments and knows how to call the right module in your application.
php代码(在您的情况下为CI)解析这些参数并知道如何在应用程序中调用正确的模块。
So basically, it's a way to always call index.php, even when the url doesn't specify index.php. 所以基本上,这是一种始终调用index.php的方法,即使url没有指定index.php。 In that way, index.php works as the front controller: it routes all requests to the right location in your application.
这样,index.php就像前端控制器一样:它将所有请求路由到应用程序中的正确位置。
^ = begin of line
( = begin group
.* = any character, any number of times
) = end group
The $1 in the second part is replaced by the group in the first part. 第二部分中的$ 1由第一部分中的组替换。
Is this a Symfony rule? 这是Symfony规则吗? The idea is to pass the whole query string to the index.php (the front controller) as a parameter, so that the front controller can parse and route it.
我们的想法是将整个查询字符串作为参数传递给index.php(前端控制器),以便前端控制器可以解析和路由它。
If the URL does not start with index.php or images or css or js or robots.txt, the string "/index.php/" is prefixed. 如果URL不是以index.php或images或css或js或robots.txt开头,则字符串“/index.php/”是前缀。
As index.php is probably an executable php app, the index.php then can read the rest of the URL from its cgi environment. 由于index.php可能是一个可执行的php应用程序,因此index.php可以从其cgi环境中读取其余的URL。 (it is stored in ${PATH_INFO})
(它存储在$ {PATH_INFO}中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.