0

I have renamed server.php file to index.php and added .htaccess code as follows

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

url is working fine now, it is working without url, but

asset()
public_path()

function are not working properly. css, js , images are not called properly.

{{ asset('assets/css/custom.css') }}

Above code to all custom.css is not working, it was working properly before. If I add public than it work properly, but that is not correct way.

{{ asset('public/assets/css/custom.css') }}

Let me know how can I add public globally to these function.

I also tried to remove url using this reference but it doesn't work. How can I remove “public/index.php” in the url generated laravel?

Jay
  • 821
  • 2
  • 18
  • 50
  • Is this a shared hosting account or your localhost? – Michel Oct 17 '17 at 15:25
  • I imagine you're doing this because you're on shared hosting, otherwise you should set your host's root folder to `/public` in your Laravel app's folder. But if you're on shared hosting why not just symlink to the public folder, like this: `ln -s /laravel-app/public /public_html` – benjivm Oct 17 '17 at 15:32

1 Answers1

0

I do three things to solve this.

I put this htaccess file in my project root folder

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

And this .htaccess configuration in my public folder, that is, project-folder/public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

then define my virtual host configuration as

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/path/projectfolder/public"
    <Directory  "/path/projectfolder/public">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require All
    </Directory>
</VirtualHost> 

This solves the problem for me

Samuel James
  • 1,528
  • 16
  • 15