htaccess的重定向URI上级目录 [英] htaccess redirect URI to parent directory
问题描述
我在主持一个网站 /无功/网络/ thesite
(Apache服务器),这是一个的Symfony2
网站所以这个文件夹中我到我的虚拟主机是指向一个网站
文件夹中。
I have a website hosted in /var/www/thesite
(apache server), it's a Symfony2
website so inside this folder I have a web
folder to which my virtual host is pointing.
所以我的虚拟主机是 www.mysite.com - >在/ var / WWW / thesite /网络
在此Web文件夹中我有一个的.htaccess
来格式化URL很好。
In this web folder I have a .htaccess
to format URL nicely.
现在,我已经添加使用 /无功/网络/ thesite / API
,API是否已实现的API 的Silex
。
我想重定向所有的请求 http://www.mysite.com/api
这个新的框架。
Now, I've added an API in /var/www/thesite/api
, the API is implemented using Silex
.
I want to redirect all request http://www.mysite.com/api
to this new framework.
于是我在 /var/www/thesite/web/.htaccess
RewriteCond %{REQUEST_URI} ^/api
RewriteRule ^api(.*)$ ../api/web/index.php [NC,QSA,L]
但我得到:
坏请求
您的浏览器发送的请求该服务器无法理解。
Your browser sent a request that this server could not understand.
我不知道如果我能在的.htaccess
访问父文件夹。我不想改变我的虚拟主机的目标目录,以避免安全漏洞。
I'm not sure if I can access parent folder in the .htaccess
. I don't want to change my virtualhost target directory to avoid security breach.
我怎样才能解决这个问题呢?
How can I solve this issue?
推荐答案
您无法路由请求的网站的文档根目录,这是的/ var
的外面/ WWW / thesite /网络。所以,你不能访问 /无功/网络/ thesite /
或 /无功/网络/ thesite / API
从内在 /无功/网络/ thesite /网络
目录。 400错误的请求是因为你的规则的目标的 ../ API /
位。
You can't route a request to outside of the site's document root, which is /var/www/thesite/web
. So you can't access /var/www/thesite/
or /var/www/thesite/api
from inside the /var/www/thesite/web
directory. The 400 Bad request is because of the ../api/
bit of your rule's target.
有些事情,你可以尝试只是使用PHP,包括做/需要的API的index.php:
Something you can try doing is just using php to include/require the api's index.php:
RewriteRule ^api/(.*)$ /index_api.php [L]
而在 index_api.php
您可以包括或要求../api/web/index.php文件。
And in the index_api.php
you can include or require the "../api/web/index.php" file.
这篇关于htaccess的重定向URI上级目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!