阿帕奇重写规则重定向所有请求子目录包含另一个的.htaccess和重写规则 [英] Apache rewrite rule to redirect all request to subdirectory containing another .htaccess and rewrite rules

查看:123
本文介绍了阿帕奇重写规则重定向所有请求子目录包含另一个的.htaccess和重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网络服务器公共和私人项目。我把一切什么是公共到Web服务器的根,我有一个私人文件夹中有我只能从本地网络(通过的.htaccess在那里设置)到达。

I have public and private projects on my webserver. I put everything what is public into the webserver root, and I have a private folder there which I can only reach from local network (set by .htaccess in there).

我想简单地把每一个私人项目中的私人文件夹中,并自动处理请求,但希望的URL看起来像他们从Webroot公司提供。结果
例如,如果有私人/ PROJECT1 我想使用的网址 http://example.com / PROJECT1 服务于该文件夹,并且不希望更改URL。

I want to simply put every private projects in the private folder and handle the requests automatically, but want the URLs look like they are served from webroot.
For example if there is private/project1 I want to use the URL http://example.com/project1 to serve that folder and don't want to change the URL.

这个简单的重写:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ private/$1           

的作品,但是当我有一个私人/项目2 另一个的.htaccess

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project2/

<Files .*>
       Order Deny,Allow
       Deny From All
</Files>

# Allow asset folders through
RewriteRule ^(assets/.+) - [L]

# Protect files from being viewed
RewriteRule ^(uploads.+) - [F,L]


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

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

</IfModule>
Options -Indexes

那么静态内容将出现,但链接已断开。
我应该怎么修改工作?

then the static content will appear, but the links are broken. What should I modify to work ?

另外,如果我有一个私人/项目3 键,浏览到 http://example.com/project3/ 是没有问题的,但是当我浏览到 http://example.com/project3 (无拖尾/)的URL将显示为 http://example.com/private/project3/ 在浏览器中。为什么呢?我怎样才能避免?

Also if I have a private/project3 and browse to http://example.com/project3/ there is no problem, but when I browse to http://example.com/project3 (without the trailing /) the URL will be visible as http://example.com/private/project3/ in the browser. Why ? How can I avoid that ?

推荐答案

所有你在你的情况下,需要的是mod_alias中。

All you need in your case is mod_alias.

然后为你的私人项目,如:

Then serve your private project like:

Alias /project3 /apache/htdocs/private/project3

和使用的.htaccess你会控制访问权限。

And with .htaccess you will control access rights.

如果你想控制它,无需重新启动服务器,你可以尝试用下面的配置来实现这一点,可以放置在.htaccess文件:

If you want to control it without restarting server, you can try to achieve this with following config, that can be placed in .htaccess file:

RewriteRule ^/(project1)$ /private/$1/index.html
RewriteRule ^/(project1/)(.*)$ /private/$1$2

index.html的 - 为您的项目中的任何索引文件。
这种方式的URL的公共部分将完全地访问,旁边路径的您正在使用的私人项目。
您还可以添加的RewriteCond检查IP并启用仅适用于本地网络重写。

index.html - any index file for your project. This way public part of URL's will be completly accessible, beside path's you are using for the private projects. You also can add RewriteCond to check IP and enable rewriting only for your local network.

这篇关于阿帕奇重写规则重定向所有请求子目录包含另一个的.htaccess和重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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