rodro1

Remove laravel public from rout

Jan 26th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url
  2. =====================================
  3. Renaming the server.php to index.php (no modifications)
  4. Copy the .htaccess from public folder to root folder (like rimon.ekjon said below)
  5. Changing .htaccess it a bit as follows for statics:
  6. ------------------------------
  7.  
  8.  
  9. ON htaccess
  10. ================
  11. RewriteEngine On
  12.  
  13. RewriteCond %{REQUEST_FILENAME} !-d
  14. RewriteRule ^(.*)/$ /$1 [L,R=301]
  15.  
  16. RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
  17. RewriteCond %{REQUEST_FILENAME} !-d
  18. RewriteCond %{REQUEST_FILENAME} !-f
  19. RewriteRule ^ index.php [L]
  20.  
  21. RewriteCond %{REQUEST_FILENAME} !-d
  22. RewriteCond %{REQUEST_FILENAME} !-f
  23. RewriteCond %{REQUEST_URI} !^/public/
  24. RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
  25.  
  26.  
  27. STEP 2//
  28.  
  29. That's working for me. But all resource files in /public directory couldn't find and request urls didn't work, because I used asset() helper.
  30.  
  31. I changed /Illuminate/Foundation/helpers.php/asset() function as follows:
  32.  
  33. function asset($path, $secure = null)
  34. {
  35.    return app('url')->asset("public/".$path, $secure);
  36. }
  37. Now everything works :)
  38.  
  39. Thank you @rimon.ekjon and all of you.
Advertisement
Add Comment
Please, Sign In to add comment