简体   繁体   English

目录内部的Mod_Rewrite不正确匹配

[英]Mod_Rewrite inside directory not matching correctly

So I've got a root folder with this as it's .htaccess (it's a WordPress build): 所以我有一个根文件夹,因为它是.htaccess(这是一个WordPress版本):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

and I've got a subdirectory called safetytraining-2 inside it. 我里面有一个名为safetytraining-2的子目录。 Requests to the sub directory work fine, and I've got a file in safetytraining-2 called true.php and it's contents are this: 到子目录的请求工作正常,我在safetytraining-2中有一个名为true.php的文件,其内容如下:

<html>
   <body>
      <?php var_dump($_GET);
      ?>
   </body>
</html>

Now inside safetytraining-2, I've got a .htaccess that I'm trying to test mod_rewrite with. 现在在safetytraining-2内部,我有一个.htaccess试图用来测试mod_rewrite。 Here's it's contents: 内容如下:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond  %{THE_REQUEST}      ^true\.php(.*)$
   RewriteRule  ^true\.php(.*)$     -                   [L]

   RewriteRule  ^(.*)$          true.php?p=$1       [L]
</IfModule>

Now here's the problem. 现在是问题所在。 When I go to website.com/safetytraining-2/foobar I get this for output: 当我转到website.com/safetytraining-2/foobar时,我会得到以下输出:

array(1) { ["p"]=> string(8) "true.php" }

It's really confusing the crap out of me. 这真让我感到困惑。 I put in the first rule with the condition to try and stop apache from recursively applying the rewrite rule, but I'm guessing it didn't help. 我输入了第一个规则,条件是尝试阻止apache递归地应用重写规则,但是我猜它没有帮助。 No matter what I put after /safetytraining/, I keep getting this output. 不管我放在/ safetytraining /之后是什么,我都会不断获得此输出。 Any help here guys? 大家有帮助吗? You can view the page at athanclark.com/safetytraining-2. 您可以在athanclark.com/safetytraining-2上查看页面。 Any help would be awesome!! 任何帮助都是极好的!!

I just figured it out. 我只是想通了。 Make sure you check your Apache version!!! 确保检查您的Apache版本!!! Versions 1.x don't recognize Perl-compatible regular expressions, but rather use POSIX Extended regular expressions. 1.x版无法识别与Perl兼容的正则表达式,而是使用POSIX扩展正则表达式。 Rewriting the .* s above to [A-Za-z0-9/=-_']+ works for me. 将上面的.*重写为[A-Za-z0-9/=-_']+对我[A-Za-z0-9/=-_']+ I'll have to read up on POSIX-style ones more to see how to accept periods (.), but it works for now. 我将不得不继续阅读POSIX风格的内容,以了解如何接受句点(。),但它现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM