【发布时间】:2010-09-26 14:31:43
【问题描述】:
如何使用 apache2 通过一个脚本处理所有请求?如果可能的话,不要使用模组。
【问题讨论】:
如何使用 apache2 通过一个脚本处理所有请求?如果可能的话,不要使用模组。
【问题讨论】:
生成诸如/index.php/topic/4/thread/3/ 之类的URL,然后检查$_SERVER['PATH_INFO']。或者只使用普通查询字符串并使用$_GET。
【讨论】:
我已经用 DocumentRoot 做到了:
DocumentRoot *site*/index.php
它会生成警告,但它正在工作:
Warning: DocumentRoot [*site*/index.php] does not exist
【讨论】:
使用 mod_rewrite,真的。这就是它的前身。将这样的内容放入 .htaccess 或 apache 配置中:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|javascript|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
这会将所有请求发送到您可能希望用于 CSS、图像、javascript 的某些子目录以及您希望可用的文件(例如 robots.txt 或 favicon.ico)到您的 index.php 文件,以及请求的实际文件添加到 URL 以便 index.php 可以处理请求。
【讨论】: