从 URL“删除”公共文件夹后,Laravel 5 中没有样式

Bra*_*low -1 php .htaccess laravel

我需要 Laravel 5 的帮助。如果这很重要,我会使用 xampp。我通过将 .htaccess 文件复制到站点的主目录,从 URL 中删除了一个公共文件夹。比我将“server.php”文件重命名为“index.php”。这最终帮助我从 URL 中删除了那个烦人的文件夹。但是,现在我在该项目的页面上没有任何样式。当我在浏览器中打开它们时,我看到没有 CSS 的 HTML 页面。有人可以帮我吗?我想张贴图片来帮助你们理解我所看到的,但我没有足够的声誉来做到这一点。谢谢。

Ste*_*man 6

不要将您的重命名server.phpindex.php. index.php您的public目录中已经有一个。将其重命名为server.php.htaccess在您的 web 根目录中创建一个文件,并将其粘贴到该.htaccess文件中:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public/
    RewriteRule ^(.*)$ public/$1 [L] #relative substitution
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我用过这个 .htaccess在本地开发过程中了一段时间,它工作得很好。请记住,对于生产,您不会想要这样做。

您不应该需要更改任何其他内容。让我知道它是否有效!


这是web.config用于 IIS 开发的版本:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Move to index.php">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:0}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
         <httpProtocol>
            <customHeaders>
                <add name="X-UA-Compatible" value="IE=11" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)