我的网站结构如下:
root
|
|----- .htaccess
|----- public
|
|----- index.php (has all Autoload classes)
|----- application
| ---- controllers
| ---- models etc
现在您可能已经注意到我的Root目录中没有index.php/.html
,我故意这样做,因为我希望服务器按.htaccess
重定向。
如果您作为用户访问网站说:
,我想实现这一目标http://localhost/testRedirect then it shall point to `public` folder
在目录中未在网址中显示public
。
我尝试过来自SO的解决方案,声称像我想要的那样工作:
解决方案1 [这只是显示目录结构:(]
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteRule ^(/)?$ public [L]
解决方案2 [给出404 :(]
RewriteEngine on
RedirectMatch ^/$ /public/
解决方案3 [它重定向但在网址中显示public
。
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTP_HOST} ^localhost\$
#RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*) http://localhost/testRedirect/$1 [R=301,L]
RewriteRule ^$ public [L]
请建议一些不错的工作htaccess
答案 0 :(得分:0)
的GAG,
为此,在运行服务器时,将文档根目录设置为/public
文件夹。
如果您使用的是apache ,请将其放在网站设置的虚拟主机中。
DocumentRoot "/path/to/project/public"
参考:https://httpd.apache.org/docs/current/mod/core.html#documentroot
如果您使用的是nginx ,请将以下内容放入网站设置的server{}
。
root /path/to/project/public;
对于cPanel,请执行以下操作
根据原始海报细节。 BigRock在https://support.bigrock.com/index.php?/Knowledgebase/Article/View/613/9/adding-an-additional-domain-to-your-multi-domain-linux-hosting
上有一个教程