简体   繁体   English

Mod_rewrite重定向到特定文件

[英]Mod_rewrite redirect to specific file

I will begin by showing you my code and then I will explain what I'm trying to achieve. 我将首先向您展示我的代码,然后再说明我要实现的目标。

RewriteEngine On

RewriteRule ^core$ library/core.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^$ public/ [L]

RewriteRule ^(.*)$ public/$1 [L]

I am using core.php as a processor file for several request sent by ajax. 我正在使用core.php作为ajax发送的多个请求的处理器文件。 When I make the request, it will be something like " http://mysite/core " and I want it to make through the .htaccess file and directly to " http://mysite/library/core.php ". 当我发出请求时,它将类似于“ http:// mysite / core ”,我希望它通过.htaccess文件发出并直接发送至“ http://mysite/library/core.php ”。 I tested it and it runs ok up to that line (I guess it would have been odd not to). 我对其进行了测试,并且可以正常运行(我猜这很奇怪)。 However, if the request is not " http://mysite/core ", I want to test if that request is neither an existent file, nor a folder, and if it ain't any of those, I want to: 但是,如果请求不是“ http:// mysite / core ”,我想测试该请求是否既不是文件也不是文件夹,并且如果它不是其中的任何一个,我想:

If I remove the last RewriteRule, everything works fine. 如果删除最后一个RewriteRule,一切正常。 However, if I let it be, (even if I access " http://mysite/core ") it keeps redirecting me to " http://mysite/public/library/core.php ". 但是,如果允许的话(即使我访问“ http:// mysite / core ”),它也会一直将我重定向到“ http://mysite/public/library/core.php ”。 I can't figure out what's happening. 我不知道发生了什么事。 It's like he's not aware of my [L] flag within the first RewriteRule. 就像他不知道我的第一个RewriteRule中的[L]标志一样。

Any help would be much appreciated. 任何帮助将非常感激。 Thanks in advance. 提前致谢。

Have it this way: 有这种方式:

RewriteEngine On

RewriteRule ^core$ library/core.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]

RewriteCond is only applicable for very next RewriteRule . RewriteCond仅适用于下一个RewriteRule

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

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