本文介绍了htaccess的路由到子目录中的服务器?性能/加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有可能使用.htaccess文件,直接击溃我的域名到子目录我的服务器上?

I wonder if it is possible to use an .htaccess file to rout my domain directly to a subdirectory on my server?

我从一个普通webhoster在我的domain.com连接到我的根我的服务器的目录买了虚拟主机包。我不知道它在某种程度上可以将.htaccess文件上传到我的根目录我的服务器上自动击溃domain.com(的index.php或/index.html),以domain.com/some-directory/~~V ...

I bought a webhosting package from a regular webhoster where my domain.com is connected to my root directory of my server. I wonder if it is somehow possible to upload a .htaccess file to my root directory on my server that automatically routs domain.com (/index.php or /index.html) to domain.com/some-directory/ …

当然,我不希望在地址栏更新到domain.com/some-directory。我想我的正常域名刚刚从子目录,而不是我的根目录抓住它的文件。

And of course I don't want the addressbar to update to domain.com/some-directory. I want my regular domain just to grab its files from the subdirectory instead of my root directory.

只是为了我的服务器上更好地了解。

Just for better overview on my server.

所以,再调用mydomain.com当它呈现的index.html(或.PHP)从我的服务器上我的根目录。不过,我想mydomain.com呈现/subdirectory/index.html。

So again, when calling mydomain.com it renders index.html (or .php) from my root directory on my server. However I want mydomain.com to render /subdirectory/index.html.

如果这是可能的,我该怎么办呢?这在某种程度上是坏?有什么我没有想到的,例如是否有更长的加载时间之类的东西与方法?

If this is possible, how can I do it? Is this bad in some way? Is there something I didn't think of, e.g. are there longer loading times or anything like that with that approach?

感谢你在前进。马特

更新:或者这可能与我的网络管理员面板上的DNS设置。我可以编辑所有DNS条目。

update: or is this possible with a DNS setting on my web-admin-panel. I'm able to edit all DNS entries.

推荐答案

尝试把这个在htaccess的文件在你的文档根目录:

Try putting this in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/some-directory/
RewriteCond %{DOCUMENT_ROOT}/some-directory%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/some-directory%{REQUEST_URI} -d
RewriteRule ^(.*)$ /some-directory/$1 [L]

请记住,如果您尝试访问目录和失踪斜线,mod_dir将浏览器重定向到与结尾的斜线的网址,并会揭露/一些目录/".

Keep in mind if you try to access a directory and are missing a trailing slash, mod_dir will redirect the browser to the URL with the trailing slash and will expose "/some-directory/".

修改

此外,在2 -f -d 的条件,以确保该请求实际上是一种资源存在。这不是必须的,如果你有进一步的htaccess的文件重写规则,你可能不希望这些。他们保证,如果有人要求一些虚假的URL,404邮件将被处理的 /一些目录/ 目录之外。否则,404消息将沿着线的东西:

Additionally, the 2 -f and -d conditions are to make sure the request is actually for a resource that exists. This isn't required, and if you have further htaccess files with rewrite rules, you probably don't want these. They ensure that if someone requests some bogus URL, the 404 message will be handled outside of the /some-directory/ directory. Otherwise the 404 message will say something along the lines of:

所请求的网址/一些目录/ blahblahblah在此服务器上找到。

揭露这一切正在通过路由/一些目录/

这篇关于htaccess的路由到子目录中的服务器?性能/加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 12:10