使用mod_rewrite将路径转换为查询字符串变量


Convert path to query string variable using mod_rewrite

我正在尝试让Apache发送:
http://mydomain.com/these/are/arguments/mmmk

:
http://mydomain.com/?pages=these/are/arguments/mmmk

使$_GET['pages']显示these/are/arguments/mmmk

我已经将'AllowEncodedSlashes'设置为On。

规则需要能够处理尾随斜杠,当没有子页面时(如http://mydomain.com)

有人知道如何完成这项任务吗?

为了不重写图像/脚本,您需要确保文件或目录首先不存在于您的。htaccess文件

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Rewrite everything else through the pages parameter 
  RewriteRule ^(.+)$ /?pages=$1 [L]