1

人们,我遇到了htaccess的问题。我正在使用 codeigniter 作为框架。我当前使用的代码是:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9_-]+)\.example\.(.*+) [NC]
RewriteCond %{REQUEST_URI} /index([0-9]+) [NC]
RewriteRule .* /index.php/main_controller/method/%1 [QSA,L]

现在我想做的是将 %1 作为一个值发送到我的 'main_controller' 控制器的名为 'method' 的方法。问题:不是发送进来的值([a-zA-Z0-9_-]+),而是发送进来的值([0-9]+),如果我发送%2应该是这种情况....我想发送传入的值([a-zA-Z0-9_-]+),比如说,如果 url 是

somevalue.example.com/index33

它正在发送33而不是somevalue

4

2 回答 2

1
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.(.*+) [NC]
RewriteRule /index([0-9]+) /index.php/main_controller/method/%1/$1 [QSA,L]

所以,愚弄我。要从 URI 中获取变量,您不必将其放入 REQUEST_URI,只需将其放入 Rewrite rule 即可,RewrideCond 中的变量是在 %1 中获得的,而 ([0-9]+) 中的变量是从 RewriteRule /index([0 -9]+) 获得 1 美元。希望它也可以帮助其他人

于 2012-05-31T09:23:19.180 回答
1
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} /index([0-9]+) [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.(.*+) [NC]
RewriteRule .* /index.php/main_controller/method/%1 [QSA,L]
于 2012-05-31T09:07:25.437 回答