配置搜索引擎友好的 url (mod_rewrite)
我想至少了解一点 .htaccess
的工作原理。我正在使用 zend 框架中的 .htaccess
(因为这是我经常使用的)
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
第一行来设置环境变量,好吧,简单的 enuf,但是后续行是做什么的? -s -l [NC,L]
等是做什么用的。从 apache 文档 我可以看到
-s< /code> - 指“具有大小的常规文件”。只是好奇是否有非常规文件?
-l
- 指的是符号链接 - 那是什么-d
- 指的是目录REQUEST_FILENAME
- 文件或脚本的完整本地文件系统路径匹配请求REQUEST_URI
- HTTP 请求行中请求的资源。
假设我浏览到“http://localhost/some/path/here
”。 REQUEST_FILENAME
& 会是什么? REQUEST_URI
等于?
无论如何,我当前将规则解释为好像
- 请求是针对具有大小的文件,或者
- 请求是针对链接,或者
- 请求是针对目录
- ...做某事...
RewriteRule ^.* 做什么$ - [NC,L]
做什么?- 然后我猜将所有符合上述规则的内容路由到index.php
i want to understand at least abit on how the .htaccess
works. i am using the .htaccess
from zend framework (since thats what i use often)
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
1st line to set an environment variable, ok simple enuf, but what do the subsequent lines do? whats the -s -l [NC,L]
etc for. from the apache docs i can see that
-s
- refers to a "regular file with a size". just curious is there a non-regular file?-l
- refers to a symbolic link - whats that-d
- refers to a directioryREQUEST_FILENAME
- full local filesystem path to the file or script matching the requestREQUEST_URI
- resource requested in the HTTP request line.
assuming i browsed to "http://localhost/some/path/here
". what will REQUEST_FILENAME
& REQUEST_URI
equals to?
anyway, i interpret the rules currently as
- if the request is for a file with size OR
- if the request is for a link OR
- if the request is for a directory
- ... do something ...
- what does
RewriteRule ^.*$ - [NC,L]
do? - then i guess route everything matching the rules above to index.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 URL 指向真实的文件/目录/链接,则按原样提供 URL(第一行 RewriteRule 根本不会更改 URL)。否则,重定向到index.php。
If the URL points to a real file/dir/link, serve the URL as is (the first RewriteRule line does not change the URL at all). Else, redirect to index.php.