htaccess的指令来*不*重定向某些URL [英] .htaccess directives to *not* redirect certain URLs

查看:164
本文介绍了htaccess的指令来*不*重定向某些URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在很大程度上依赖于的.htaccess 的RewriteRules其prettyURLs(CakePHP的在我的情况),我该如何正确设置指令,以排除某些目录的应用程序从此改写?那就是:

In an application that heavily relies on .htaccess RewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is:

/appRoot/.htaccess
         app/
         static/

在默认情况下每个请求 /为approot / * 被改写为被拾起应用程序/ Web根目录/的index.php ,它正在被分析和相应的控制器行动正在调用。这是由这些指令中完成的的.htaccess

By default every request to /appRoot/* is being rewritten to be picked up by app/webroot/index.php, where it's being analysed and corresponding controller actions are being invoked. This is done by these directives in .htaccess:

RewriteBase /appRoot

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

我现在要排除的几个目录,如static /从此改写。我试着用这个的的蛋糕的规则集:

RewriteCond $1 ^(static|otherDir).*$ [NC]
RewriteRule (.*) - [L]

它的工作原理在目前为止的请求不再重写,但现在的所有的请求被跳过,即使是合法的蛋糕请求不应匹配 ^(静态| otherDir) * $

It works in so far that requests are no longer rewritten, but now all requests are being skipped, even legitimate Cake requests which should not match ^(static|otherDir).*$.

我想这些规则的一些变化,但不能得到它的工作就是我想要的。

I tried several variations of these rules but can't get it to work the way I want.

推荐答案

和正确答案iiiiis ...

And the correct answer iiiiis...

RewriteRule   ^(a|bunch|of|old|directories).* - [NC,L]

# all other requests will be forwarded to Cake
RewriteRule   ^$   app/webroot/   [L]
RewriteRule   (.*) app/webroot/$1 [L]

我还是不明白,为什么在根目录下的index.php文件被称为最初甚至代替这些指令。它现在位于

I still don't get why the index.php file in the root directory was called initially even with these directives in place. It is now located in

/appRoot/app/views/pages/home.ctp

和通过蛋糕的处理为好。有了这个在现在的地方,我想这会工作,以及(稍微改变版本麦克的建议的,未经测试):

and handled through Cake as well. With this in place now, I suppose this would have worked as well (slightly altered version of Mike's suggestion, untested):

RewriteCond $1      !^(a|bunch|of|old|directories).*$ [NC]
RewriteRule ^(.*)$  app/webroot/$1 [L]

这篇关于htaccess的指令来*不*重定向某些URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆