No styles in Laravel 5 after "removing" public folder from URL

6k Views Asked by At

I need your help with Laravel 5. I use xampp if this matters. I have removed a public folder from URL by copying .htaccess file to the main directory of the site. Than i renamed a "server.php" file to "index.php". That FINALLY helps me to kick that annoying folder from URL. BUT, now I haven't any styles on the pages of that project.When I open them in browser I see pages of HTML without CSS. Can somebody help me in this? I wanted to post pictures to help u guys understand what I see, but i haven't enough reputation do that. Thanks.

3

There are 3 best solutions below

5
Steve Bauman On

Don't rename your server.php to index.php. There is already an index.php inside your public directory. Rename it back to server.php, create a .htaccess file inside your root web directory, and paste this inside the .htaccess file:

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

I've used this .htaccess for a while during local development, and it works just fine. Keep in mind for production you wouldn't want to do this.

You shouldn't need to change anything else. Let me know if it works!


Here's the web.config version as well for IIS development:

<?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>
0
Shaddy On

Rename server.php to index.php and copy htaccess from public folder to root directory . Call css {!! asset('public/css/all.css') !!}, and add 'public/' before your css file location. Please let me know.

0
Syed Ali On

Rename server.php to index.php and copy htaccess from public folder to root directory past this in mywebsit/.htaccess

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