重定向至“看不见htaccess PHP Apache”子文件夹


Redirect to subfolder invisibly htaccess PHP Apache

我的网站结构如下:

root
 |
 |----- .htaccess
 |----- public
          |
          |----- index.php (has all Autoload classes)
 |----- application
          | ---- controllers
          | ---- models etc

现在您可能已经注意到,我的根目录中并没有index.php/.html,我故意这么做是因为我希望服务器通过.htaccess重定向。

我想实现,如果你作为一个用户访问网站说:

http://localhost/testRedirect then it shall point to `public` folder 

而不在URL中显示CCD_ 3。

我尝试了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[它重定向,但在URL中显示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

仪表,

为此,在运行服务器时,将文档根设置为/public文件夹。

如果您使用的是apache,请将其放置在网站设置的虚拟主机中。

DocumentRoot "/path/to/project/public"

参考编号:https://httpd.apache.org/docs/current/mod/core.html#documentroot

如果您正在使用nginx,请将以下内容放在网站设置的server{}中。

root /path/to/project/public;

参考编号:http://nginx.org/en/docs/

对于cPanel,执行以下操作

  • 登录cPanel
  • 在"域"部分,单击Addon Domains或Subdomains图标,具体取决于您要修改的域
  • 在页面底部的"修改域"部分,单击要修改的域的当前文档根目录旁边的图标
  • 在弹出窗口中,输入新文档根目录,然后单击"更改"

根据原始海报的详细信息。BigRock在https://support.bigrock.com/index.php?/Knowledgebase/Article/View/613/9/adding-多域linux托管的附加域