Apache的重定向htaccess的到子目录 [英] Apache Redirect in htaccess to subdirectory

查看:959
本文介绍了Apache的重定向htaccess的到子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个内部​​应用程序,需要开始在公共文件夹,目录结构如下:

I've built an in house app that needs to start in public folder, directory structure is as follows

myapp/conf
myapp/tmp
myapp/doc
myapp/public
myapp/public/css
myapp/public/js
myapp/public/index.php

如果用户安装,而不是做的myapp /公共Web根目录它根目录的子目录,然后是网址是

If a user installs it in webroot subdirectory, instead of making myapp/public the webroot, then the URLs would be

,某/ MyApp的/公/ index.php文件

somehost/myapp/public/index.php

我如何重定向与/myapp/.htaccess,使其转发一切/public/index.php,还会改变URL包含/公众。

How do I redirect with /myapp/.htaccess, so that it forwards everything to /public/index.php BUT also changes the URL to include /public.

我已经找到了如何重定向到公众,但因为我做的URL改写/公/,我需要$ _ SERVER ['REQUEST_URL']有/公/路径。

I have figured out how to redirect to public, but since i'm doing URL Rewrites in /public/, i need $_SERVER['REQUEST_URL'] to have /public/ in the path.

我想prevent获得一切(/ conf目录和/ DOC等。)

I'd like to prevent access to everything else (/conf and /doc etc..)

运气好的话?

我的尝试:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) index.php/$1 [R=301,L]
RewriteRule ^$ public [L]
</IfModule>

但是,这似乎把公众面前的myapp <​​/ code>和URL看起来像这样:本地主机/公/ MyApp的/ ,而是我需要本地主机/ MyApp的/公/

在简单来说,我希望所有的URL /不管/ *有公共追加到/不管/公共/*.

In simpler terms, I want all URLS to /whatever/* to have public appended to it /whatever/public/*.

该解决方案需要独立的域名和MyApp的名字。他们能说出的根文件夹('的myapp),无论但它始终有一个子目录名为公开。

The solution needs to be independent of the domain name and 'myapp' name. They could name the root folder ('myapp') whatever but it will always have a sub dir called 'public'.

推荐答案

尝试

RewriteEngine On
RewriteBase /myapp/

RewriteCond %{REQUEST_URI} !/public/
RewriteRule (.*) public/index.php/$1 [R=301,L]
RewriteRule ^$ public [L]

最主要的是,你需要在基础更改为您的应用程序名称。然后该规则可以保持不变。条件是需要prevent重定向循环。但是,你可能不会需要它,如果你有内部的.htaccess文件处理请求/公共/.

The main thing is you need to change the base to your app name. Then the rules can remain the same. The condition is needed to prevent redirect looping. But you probably won't need it if you have an .htaccess file handling requests inside /public/.

这篇关于Apache的重定向htaccess的到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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