有些主机不喜欢.htaccess正则表达式中的字符类吗?

时间:2013-06-15 20:51:34

标签: regex .htaccess mod-rewrite hosting character-class

我很少有这个问题,只在某些主机上。 这是我的自定义框架的.htaccess:

Options -Indexes

ErrorDocument 403 /application/views/403.htm
ErrorDocument 404 /application/views/404.htm

RewriteEngine on
RewriteRule ^index\.php$ index.php [L]

.
.
.

RewriteRule ^([\w-]+)/([\w-]+)/(.+)$ index.php?q_controller=$1&rq_action=$2&rq_param=$3 [L]
RewriteRule ^([\w-]+)/([\w-]+)$ index.php?rq_controller=$1&rq_action=$2 [L]
RewriteRule ^([\w-]+)/?$ index.php?rq_controller=$1 [L]

定义控制器,视图和参数的最后3行只是不能在某些主机上工作,所有其余的工作正常,因此显然启用了mod_rewrite。如果我将它们更改为它可行,但这不是我需要的:

RewriteRule ^(.+)/(.+)/(.+)$ index.php?rq_controller=$1&rq_action=$2&rq_param=$3 [L]
RewriteRule ^(.+)/(.+)$ index.php?rq_controller=$1&rq_action=$2 [L]
RewriteRule ^(.+)/?$ index.php?rq_controller=$1 [L]

有什么想法吗? 那些托管不支持.htaccess正则表达式中的字符类吗?

由于

1 个答案:

答案 0 :(得分:1)

我不是网址重写方面的专家,但您可以尝试两件事:

  1. 尝试使用明确的[\w-]
  2. 替换[a-zA-Z0-9_-]
  3. 尝试将[\w-]替换为[^/]