重定向根的子目录codeIgniter的应用程序,避免了死循环 [英] Redirect root to CodeIgniter app in subdir, avoiding infinite loop

查看:111
本文介绍了重定向根的子目录codeIgniter的应用程序,避免了死循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司目前已经部署了以下的.htaccess在我的codeIgniter应用程序的目录:

I currently have deployed the following .htaccess in the directory of my CodeIgniter app:

RewriteEngine On

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

在我的htdocs根以下的.htaccess:

and the following .htaccess in my htdocs root:

RewriteEngine On

# Map / to /foo.
RewriteRule ^$ /foo/ [L]

# Map /x to /foo/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/foo/
RewriteRule ^(.*)$ /foo/$1

其中foo是目录是我的codeIgniter应用程序的生命。这种重定向example.com/foo/whatever是否匹配其他目录,而其他应用程序生活(狐狸例如example.com/admin/whatever,应保持这种方式),除了example.com/whatever~~V。行为的一部分是期望的。但现在我有两个网址上的富每一页,我有example.com/foo/whatever和example.com/whatever。我想打301重定向所有请求从/富/ X为/ X,但如果我添加

Where foo is the directory were my CodeIgniter app lives. This redirects example.com/foo/whatever to example.com/whatever, except if it matches other directories where other apps live (fox example example.com/admin/whatever, which should be kept that way). That part of the behaviour is desired. But now I have two urls for every page on foo, I have example.com/foo/whatever and example.com/whatever. I want to make a 301 redirect for all requests from /foo/x to /x, but if I add

# Redirect /foo/x to /x
RewriteRule ^foo/(.*)$ /$1 [R=301,L]

到的.htaccess我明明得到一个重定向无限循环。 这里描述为一个相关的问题不工作的解决方案,因为在需要的时候它不重定向到的index.php 。我怎样才能达到我想要的?在此先感谢任何帮助,您可以提供。

to the .htaccess I obviously get a redirection infinite loop. The solution described here for a related question doesn't work, because it doesn't redirect to the index.php when needed. How can I achieve what I want? Thanks in advance for any help you may provide.

推荐答案

您也可以在 /foo/.htaccess 这个新规则来重定向 /富/ ABC / ABC

Have this new rule in /foo/.htaccess to redirect /foo/abc to /abc:

RewriteEngine On

RewriteCond %{THE_REQUEST} /foo/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=301,NE]

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

这篇关于重定向根的子目录codeIgniter的应用程序,避免了死循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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