通过 .htaccess 更改根文件夹 [英] Changing the root folder via .htaccess

查看:38
本文介绍了通过 .htaccess 更改根文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与域名关联的共享主机帐户,并且根文件夹(如果这是错误的术语,请纠正我)设置为 / 以便服务器上的所有文件都是公共的/可通过浏览器访问.

I've got a shared hosting account associated with a domain name and the root folder (correct me if that's the wrong term) is set to / so that all files on the server are public / accessible through the browser.

我可以使用 .htaccess 或其他东西将根文件夹更改为 /example.com/public/ 之类的内容吗?

Can I use .htaccess or something to change the root folder to something like /example.com/public/?

推荐答案

如果我的理解正确,以下应该有效

If I'm understanding correctly, the following should work

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

这会将所有不以 /public/ 开头的请求重定向到以 /public/ 开头的 URL.

This will redirect all requests that do not begin with /public/ to URL that does.

希望有所帮助.

这篇关于通过 .htaccess 更改根文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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