configuring search engine friendly url (mod_rewrite)

妖精的绣舞 提交于 2019-12-12 01:35:15

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/3317580/configuring-search-engine-friendly-url-mod-rewrite

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