htaccess的XAMPP - 重定向请求到特定的目录(很多情况) [英] htaccess xampp - Redirect request to specific directory (many conditions)

查看:1004
本文介绍了htaccess的XAMPP - 重定向请求到特定的目录(很多情况)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林工作的一种大规模虚拟主机的应用程序,所以我需要以下几点:

htaccess的文件的顶部:

  RewriteEngine叙述上
的RewriteCond%{ENV:REDIRECT_STATUS} ^ $
 

进出口运行XAMPP localy所以,我为了测试要求编辑我的etc / hosts文件。

1°检测主机名和重写它的主机里面的文件夹:

所以,按照上面的code我加了这一点,它工作正常(我测试):

 的RewriteCond%{HTTP_HOST} WWW \。?。* \ .. *
重写规则。*%,2 / $ 1 [NC,QSA,L]
 

当我键入 whatever.com 如果它存在于主机,而且对的/ opt / LAMPP / htdocs中/ whatever.com 浏览器里面去作为spected <文件夹/ P>

2º(问题)

解释:我需要一个像 whatever.com /管理员进入所谓的/ opt / LAMPP / htdocs中/ 管理其他目录,并通过主机名作为GET参数要求因此 whatever.com/admin internaly变成本地主机/管理/?域= whatever.com

当你SPECT我得到404和500没有找到一个解决方案。

我想这是更多钞票,以增加更多的重写COND。在伪code整个文件可能是如下

 的RewriteCond%{HTTP_HOST} WWW \。?。* \ .. *
重写规则。*%,2 / $ 1 [NC,QSA,L]
重写规则管理\ /.* \。(JS!| CSS | PHP)?/管理/域=%2 [NC,QSA,L] #REDIRECT都要求至少CSS和JS文件。
 

非常感谢。

对不起,我的英语水平。教育性系统在这里吸。

解决方案

解决的办法,我必须测试的更多,但我认为就解决了。贾斯汀Iurman非常感谢的帮助。

当然,我加入到rwrule重写规则^管理/ (。*)? $后端PHP / $ 1 ?域=%1 [L,QSA,NC ]为了重写所有文件。

这样的htaccess看起来如下:

  RewriteEngine叙述上
的RewriteCond%{ENV:REDIRECT_STATUS} ^ $

的RewriteCond%{HTTP_HOST} ^(?:WWW \)?(。+)$ [NC]
的RewriteCond%{REQUEST_URI}!^ /管理? [NC]
重写规则^(。*)$ 1%/ $ 1 [L,QSA,NC]

的RewriteCond%{HTTP_HOST} ^(?:WWW \)?(。+)$ [NC]
重写规则^管理/(.*)?$后端PHP / $ 1?域=%1 [L,QSA,NC]
 

如何,如果该请求看起来像 http://whatever.com/admin/ANYSCRIPT_OR_VOID 它去本地主机/后端PHP / ANYSCRIPT或空隙?域= whatever.com

CSS和JS文件可以作为spected了。

Im working on a kind of mass virtual hosting app so i need the following things:

top of the htaccess document:

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$

Im running XAMPP localy so, I edited my etc/hosts in order to test requests.

1º detect hostname and rewrite to its folder inside the host:

so, following the above code I added this and it works correctly (as I tested):

RewriteCond %{HTTP_HOST} www\.?.*\..*
RewriteRule .* %2/$1 [NC,QSA,L]

when i type whatever.com if it exist on hosts and there is a folder on /opt/lampp/htdocs/whatever.com browser go inside as spected

2º (the problem)

explanation: i need that request like whatever.com/admin go into other directory called /opt/lampp/htdocs/admin AND pass the hostname as a GET parameter, therefore whatever.com/admin internaly turns into localhost/admin/?domain=whatever.com

As you spect i get 404 and 500 without find a solution.

I think that is posible to add more rewrite cond.. in pseudo code entire file could be as follow

RewriteCond %{HTTP_HOST} www\.?.*\..*
RewriteRule .* %2/$1 [NC,QSA,L]
RewriteRule admin\/.*\.(!js|!css|php) /admin/?domain=%2 [NC,QSA,L] #redirect all request least the css and js files.

Many thanks.

Sorry for my english. Educative system here sucks.

解决方案

The solution, i must test more this but i think is solved. Many thanks to Justin Iurman by the help.

Of course i added to the rwrule RewriteRule ^admin/(.*)?$ BACKEND-PHP/$1?domain=%1 [L,QSA,NC] in order to rewrite all the files.

so htaccess looks as following:

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond %{REQUEST_URI} !^/admin? [NC]
RewriteRule ^(.*)$ %1/$1 [L,QSA,NC]

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^admin/(.*)?$ BACKEND-PHP/$1?domain=%1 [L,QSA,NC]

How if the request looks like http://whatever.com/admin/ANYSCRIPT_OR_VOID it goes to localhost/BACKEND-PHP/ANYSCRIPT OR VOID?domain=whatever.com

css and js files works as spected too.

这篇关于htaccess的XAMPP - 重定向请求到特定的目录(很多情况)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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