且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mod_rewrite的,PHP和.htaccess文件

更新时间:2021-08-01 04:54:43

一种方法是重写一切到处理脚本

One approach is to rewrite everything to a handling script

RewriteEngine on
RewriteBase /

# only rewrite if the requested file doesn't exist
RewriteCond %{REQUEST_FILENAME} !-s 

# pass the rest of the request into index.php to handle     
RewriteRule ^(.*)$ /index.php/$1 [L]

所以,如果你有一个请求, HTTP:// yourserver /富/酒吧/

你真正得到的是一个请求 HTTP://yourserver/index.php/foo/bar - 和你可以离开的index.php,以决定如何处理/富/条(使用$ _ SERVER ['PATH_INFO'] - 汤姆

what you actually get is a request to http://yourserver/index.php/foo/bar - and you can leave index.php to decide what to do with /foo/bar (using $_SERVER['PATH_INFO'] -tom)

您只需要修改.htaccess中的第一次。对于不存在的文件,今后所有申请就可以在PHP处理。

You only need to modify .htaccess the first time. All future requests for inexistent files can then be handled in PHP.

您可能还会发现的文档mod_rewrite的有用的 - 但保持它的简单或prepare失去大量的睡眠和头发的跟踪隐蔽的错误。

You might also find the docs for mod_rewrite useful - but keep it simple or prepare to lose a lot of sleep and hair tracking down obscure errors.