著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章原始出版、作者資訊和本聲明。否則將追究法律責任。http://blog.csdn.net/mayongzhan - 馬永占,myz,mayongzhan
原文地址:http://www.phpguru.org/#212
最近php-general mailinglist 正在討論關於mod_rewrite。我的觀點很簡單,不需要,請看下文:
/rental/property/23425
你可能認為上面的那個地址是rewrite的結果。你錯了。是在.htaccess中使用了如下內容:
<Files rental>
ForceType application/x-httpd-php
</Files>
檔案被apache當作PHP指令碼來執行。意思是你可以使用REQUEST_URI這個伺服器變數來得到提交的URL,然後顯示內容。
Recent discussion on the php-general mailing list regarding mod_rewrite. My opinion is that if your needs are simple - it's not necessary. Consider:
/rental/property/23425
You may think that mod_rewrite is necessary here. It's not. Simply place this in a .htaccess file:
<Files rental>
ForceType application/x-httpd-php
</Files>
Now the file "rental" will be parsed by Apache as a PHP script. This means you can use the REQUEST_URI server variable to get the requested URI and show the appropriate content.
This is exactly how the "static" directory is done on this site. It's actually not a directory at all, but a PHP file that looks at the URL and determines the correct content to show.