HTACCESS:将域根目录更改为子目录 [英] HTACCESS: Change domain root to sub-directory

查看:113
本文介绍了HTACCESS:将域根目录更改为子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用子目录作为我的一个域的根文件夹。使用.htaccess,我使用mod_rewrite来完成工作。这是我已经拥有的代码:

I'm trying to use a sub-directory as the root folder for one of my domains. Using .htaccess, I use mod_rewrite's to get the job done. Here's the code I already have:

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ /domain/index.php [L]

这可以完成工作,但不是全部。例如:

This gets the job done, but not entirely. For example:

如果我转到 http://domain.com/ ,它将在文件夹中显示 index.php 。如果我转到 http://domain.com/test/ ,它将显示以下内容(或403): test 文件夹。 (如果我转到 http://domain.com/test (用于快捷方式) ,甚至显示文件夹),我被重定向到 http://domain.com/domain/test/

If I goto http://domain.com/, it displays index.php from inside the domain folder. If I goto http://domain.com/test/, it will display the contents (or 403) of the test folder. BUT if I goto http://domain.com/test (for use of shortcuts, or even to display the folder) I get redirected to http://domain.com/domain/test/.

这不应该发生。如果有的话,它会从.htaccess中屏蔽(如果正在使用测试),或者应该转到 http:// domain .com / test / 。我试图找出解决方法,但我做不到。因此,我正在寻求您的帮助! :)

That is not supposed to happen. If anything, it either does a mask from the .htaccess (if test is being used) or should just goto http://domain.com/test/. I have tried to figure out a way around this, and I cannot. So I am seeking your help! :)

任何帮助和帮助都将不胜感激。

Any and all help is greatly appreciated.

推荐答案

试试看:它有点粗糙,但是应该做你想做的。有点混乱:我尝试做的某些事情取决于您的RewriteBase(您可能需要删除一个或多个/字符)。

Try this: its a little crude, but should do what you want. There is a little bit of confusion: some of what I've tried to do will depend on your RewriteBase (you might need to remove one or more / characters).

我基本上已经添加了一个初始块,该块专门查找您的 / domain / 文件夹中不以斜杠结尾的目录并添加了一个让我知道它是否完全有效。

I've basically added an initial block that specifically looks for directories within your /domain/ folder that don't end with a trailing slash and added one. Let me know if it works at all.

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond /domain/%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /domain/$1/

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ /domain/index.php [L]

这篇关于HTACCESS:将域根目录更改为子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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