HTACCESS:将域根目录更改为子目录
我正在尝试使用子目录作为我的域之一的根文件夹。使用 .htaccess,我使用 mod_rewrite 来完成工作。这是我已经拥有的代码:
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]
这完成了工作,但还没有完全完成。例如:
如果我转到 http://domain.com/,它会显示 index.php
从 domain
文件夹中。如果我转到 http://domain.com/test/,它将显示以下内容(或 403) test
文件夹。 但是如果我转到http://domain.com/test(使用快捷方式,甚至显示文件夹)我被重定向到 http://domain.com/domain/test/。
这是不应该发生的。如果有的话,它要么从 .htaccess 执行掩码(如果正在使用测试),要么应该转到 http://domain .com/test/。我试图找到解决这个问题的方法,但我做不到。所以我寻求你的帮助! :)
非常感谢任何和所有的帮助。
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:
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/.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个:它有点粗糙,但应该做你想做的事。有一点混乱:我尝试做的一些事情将取决于您的 RewriteBase (您可能需要删除一个或多个 / 字符)。
我基本上添加了一个初始块,专门查找 /domain/ 文件夹中不以尾部斜杠结尾的目录,并添加了一个。让我知道它是否有效。
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).
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.
评论者是对的,如果您想
使用子目录作为我的域之一的根文件夹
,只需在您的apache虚拟主机配置中配置它(DocumentRoot)。The commenter is right, if you want to
use a sub-directory as the root folder for one of my domains
, just configure it in you apache virtual host configuration (DocumentRoot).上面的代码成功地完成了我想要它做的一切。
The above code successfully does everything I wanted it to do.
像这样使用 RewriteBase:
RewriteBase /f2f/f2fweb
Use RewriteBase like this:
RewriteBase /f2f/f2fweb
对我有帮助的是我主机上的 auto.htaccess 生成器!!!!
What helped me is auto.htaccess generator on my host!!!!