Mod_rewrite将所有内容转发给index.php的params

Kyl*_*iss 1 apache mod-rewrite

我怎样才能获得除了重写为index.php的参数文件之外的任何内容?我正在使用apache,mod_rewrite等.

Nev*_*kes 6

如果你想重写任何不是常规文件请求的东西,我会用它:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/index\.php -f
    RewriteRule ^(.*)$  /index.php?page=$1 [QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

这样您就不必担心自己是否遵循某种URL格式进行重写 - 您可以在服务脚本中进行相应的测试和操作.