mel*_*yal 2 regex apache mod-rewrite codeigniter
谁能解释一下这个mod_rewrite规则在做什么?
我正试图评论该文件,但代码似乎与我认为它正在做的相反
# 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]
Run Code Online (Sandbox Code Playgroud)
浏览器向服务器发送请求(Apache,因为您正在使用mod_rewrite):
获取个人资料/编辑
Apache接受此请求,并在其配置文件中看到您已将其配置为通过mod_rewrite传递所有请求.因此,它将字符串'profile/edit'发送到mod_rewrite.然后,Mod_rewrite将您指定的规则应用于它,然后将请求(以我在上一篇文章中解释的方式)转换为'index.php/profile/edit'.mod_rewrite完成后,Apache继续处理请求,并看到'哦,这家伙正在请求文件index.php'.所以它调用php解释器然后解析并执行index.php - 并将'/ profile/edit'作为参数.php代码(在您的情况下为CI)解析这些参数并知道如何在应用程序中调用正确的模块.
所以基本上,这是一种始终调用index.php的方法,即使url没有指定index.php.这样,index.php就像前端控制器一样:它将所有请求路由到应用程序中的正确位置.
| 归档时间: |
|
| 查看次数: |
1016 次 |
| 最近记录: |