如何使用htaccess使子文件夹像文档根一样工作? [英] How do I make a subfolder act like a document root using htaccess?
问题描述
站点位置:
该网站加载了很多带有绝对URL的图像,例如/image/image.png。
The website loads lots of images with an absolute url such as /image/image.png.
我需要该请求转到:
http://localhost/~username/website/image/image.png
代替
http://localhost/image/image.png 。
I need that request to go to: http://localhost/~username/website/image/image.png instead of http://localhost/image/image.png.
我也需要这样做,以不影响任何其他文件夹或根文件夹。这样,如果愿意,我也可以访问 http://localhost/image/image.png 。
I also need this to not affect any other folders or the root folder. So that I could also access http://localhost/image/image.png if I wanted to.
是否有某种方法可以使它从该子文件夹中请求重定向?
Is there some way of making it so that when it's requested from this subfolder to redirect?
我想要诸如/css/something.css和/image/image.png的绝对引用指向/subdirectory/css/something.css和/subdirectory/image/image.png。这样,我不必重写所有绝对引用。因此,我不想修改根目录。
I want the absolute reference like /css/something.css and /image/image.png to points to /subdirectory/css/something.css and /subdirectory/image/image.png. That way I don't have to rewrite all the absolute references. So, I don't want to modify the root directory.
我想知道是否设置了不允许子目录网站没有的虚拟主机。能够访问根。我根本不需要从该文件夹进行根访问。
I'm wondering if setting up a virtual host that would not allow the subdirectory "website" to have no ability to access the root. I don't ever need root access from this folder.
推荐答案
您可以在根.htaccess或Apache /虚拟主机配置:
You can use this rule in root .htaccess OR in Apache/vhost config:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/~
RewriteRule ^(.*)$ ~username/website/$1 [L]
这篇关于如何使用htaccess使子文件夹像文档根一样工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!