首页 > 解决方案 > 如何从laravel子文件夹中的url中删除public

问题描述

我想将我的 laravel 网站托管在如下子文件夹中:-

public_html/ecommerce/

实际上,我在 public_html 中还有一个 laravel 网站,因为我已经从 htaccess 下面的 url 中删除了 public

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule    ^$    public/    [L]
RewriteRule    (.*) public/$1    [L]
</IfModule>

但是如果在 public_html/ecommerce 中添加相同的 htaccess 它根本不起作用,因为它可能是由于子文件夹

我在谷歌上搜索了一些人告诉以下几点: -

1) Rename server.php to index.php 
2) copy .htacces from public to root
 This is working but my all assets path like css jss are not fetching for that i need to add public in each asset link.

任何人都可以帮助我如何仅在 htccess 级别上做。提前致谢

标签: phplaravel.htaccess

解决方案


你的目录结构必须是,

public_html

  • laravel_app1
  • laravel_app2
  • laravel_app3

在每个 laravel 应用根目录下创建 .htaccess 即 laravel_app1/.htaccess、laravel_app2/.htaccess 等。在每个 .htaccess 中添加这样的规则

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

最后你可以访问网站,yourdomain.com/laravel_app1 yourdomain.com/laravel_app2 等等


推荐阅读