使用的.htaccess设置一个分目录根目录 [英] Using .htaccess to set a sub directory as root directory
问题描述
有没有办法使用htaccess的告诉子目录作为根整个网站?
Is there a way to use htaccess to tell a subdirectory to act as the root for the entire site?
例如,如果我有在 HTTP网站://本地主机/测试网站/ ,并在它的index.php文件我有一个参考使用以下code样式表。
For example, if I had a website under http://localhost/testsite/ and in it's index.php file I had a reference to the stylesheet using the following code..
<link rel="stylesheet" type="text/css" href="/css/layout.css" />
我能然后进行负载/localhost/testsite/css/layout.css?
Could I then make that load /localhost/testsite/css/layout.css?
要解决这个问题,我设置了本地主机的子域的每个网站,虽然作品,是不理想的。
To get around this problem, I set up localhost subdomains for each site which although works, is not ideal.
非常感谢。
推荐答案
如果您想保留HREF =/ CSS / layout.css中的一部分,那么,你可以设置一个重写规则。你一定要小心,不要以/测试网站重定向任何东西(或你会结束了一个循环)。
If you want to keep the 'href="/css/layout.css"' part, then yes, you can set up a rewrite rule. You just have to be careful not to redirect anything starting with /testsite (or you'll end up with a loop).
赞(根的.htaccess):
Like (in root .htaccess):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/testsite/.*$
RewriteRule ^(.*)$ /testsite/$1 [QSA,L]
在这里,您将能够访问你的layout.css中的文件或者从:
There, you will be able to access your layout.css file either from:
HTTP://localhost/testsite/css/layout.css
或
HTTP://localhost/css/layout.css
这篇关于使用的.htaccess设置一个分目录根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!