我遇到了 mod_rewrite 问题,我认为这可能是由我的 .htaccess 之外的其他配置文件中的全局规则引起的,需要查看是否有办法显示所有有效的 RewriteRules。
具体来说,我的问题是http://mydomain.com/pages/test工作正常(重定向到 pages/index.php),但是http://mydomain.com/pages/test-page返回 404 错误。任何在页面/中断后包含破折号的内容。其他一切都有效。重写规则应该是:如果找到 /pages/file.xx,则显示它。否则将其发送到 /pages/index.php
我的 .htaccess
重写引擎开启 RewriteBase /pages RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d 重写规则。- [大] 重写规则 ^([_0-9a-zA-Z-]+/)?(am-.*) $2 [L] 重写规则 ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ 重写规则 (.*)$ /pages/$1/ [R=301,L] 重写规则 ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 重写规则 ^([a-zA-Z0-9\-_\/\s]+)/?$ /pages/index.php [L]
编辑 打开 RewriteLog,我得到以下 URL “domain.com/pages/test-string”:
xx.xx.xx.xx - - [03/Oct/2012:11:34:15 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 通过 /hsphere/local/home/domain/domain.com/pages/test-string xx.xx.xx.xx - - [03/Oct/2012:11:34:16 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 通过 /hsphere/local/home/domain/domain.com/splash/test-string
这是 URL “domain.com/pages/test”的结果
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 重写测试 -> /pages/test/ xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 使用 http://domain.com/pages/test/ 显式强制重定向 xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 试图用 /pages 替换前缀 /hsphere/local/home/domain/domain.com/pages/ xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 转义 http://domain.com/pages/test/ 以进行重定向 xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 重定向到 http://domain.com/pages/test/ [REDIRECT/301] xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 重写 test/ -> /pages/index.php xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 试图用 /pages 替换前缀 /hsphere/local/home/domain/domain.com/pages/ xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/ local/home/domain/domain.com/pages/] 内部重定向与 /pages/index.php [内部重定向] xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#17c144e0/initial/redir#1] (1) [per- dir /hsphere/local/home/domain/domain.com/pages/] 通过 /hsphere/local/home/domain/domain.com/pages/index.php