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

查看:243
本文介绍了通过更改.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]

这将重定向不以 /公/ 来,做URL的请求。

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

希望有所帮助。

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

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