我想使用单个php脚本处理对域的所有请求。
例如:
www.domain.com/something.php -> would be loading -> www.domain.com/process.php?u=something.php
www.domain.com/anything -> would be loading -> www.domain.com/process.php?u=anything
www.domain.com/sub/dir/x -> would be loading -> www.domain.com/process.php?u=sub/dir/x
但是process.php永远不应该直接在浏览器上打开,我想像内部重定向一样。
有人可以告诉我如何使用htaccess和mod_rewrite来执行此操作?
答案 0 :(得分:3)
将这些行放入.htaccess
文件中:
RewriteEngine On
RewriteRule (.*) process.php?u=$1 [QSA,L]
这将告诉Apache使用process.php
而不是实际请求的页面。
您很可能还需要在RewriteRule
行之前添加这些行,以告知Apache按原样处理现有文件,否则您的images / css / javascript文件也将由process.php
处理
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d