在 htaccess 重定向中发送了错误的值


Wrong value sent in htaccess redirect

人们,我在htaccess上遇到了问题。我使用代码点火器作为框架。im 当前使用的代码是:

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_-]+),例如,如果网址是

somevalue.example.com/index33

它发送的是33而不是somevalue

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]
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,只需将其放入 i 重写规则,来自 RewrideCond 的变量是在 %1 中获得的,而来自 RewriteRule/index([0-9]+) 的 ([0-9]+) 的变量是在 $1 中获得的。希望它也能帮助其他人