配置搜索引擎友好的 url (mod_rewrite)

发布于 2024-09-11 11:03:44 字数 1156 浏览 3 评论 0原文

我想至少了解一点 .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 directiory
  • REQUEST_FILENAME - full local filesystem path to the file or script matching the request
  • REQUEST_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦冥 2024-09-18 11:03:44

如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文