I would be very grateful if someone could answer.
I am trying to install my laravel project to virtual host. The server
runs on nginx.
Everything is ok except assets file.
The problem is the server does not load assets files. To be more exact:
asset()
function doesnt point to public path.
But the URLs (routes) are working perfect.
I copied htaccess files from public path to root.
Here is my htaccess files content:
<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}]
Any helps guys! Thank you very much!
Related
I'm trying to set up my laravel project made on a local appache server on a internal shared hosting service of my university.
The problem I am having is that except for the routes related to my laravel projects Authorisation/Authentication (HomeController) stuff other routes do not work as the subdomain for those routes are not automatically added like this for them (bolded part being the subdomain):
https://www.cs2410-web02pvm.aston.ac.uk/~khane2/home
Here is my web.php of my laravel project:
Route::get('/animal_user_change_status/{animal_id}/attach', 'Animal_usersController#attach');
Route::get('/animal_user_change_status/{animal_id}/{user_id}/detach', 'Animal_usersController#detach');
Route::get('/animal_user_change_status/{animal_id}/{user_id}/Accept', 'Animal_usersController#setAcceptToStatusColumn');
Route::get('/animal_user_change_status/{animal_id}/{user_id}/Reject', 'Animal_usersController#setRejectToStatusColumn');
Route::get('/viewuserdata', 'Animal_usersController#viewUserData');
Route::get('/viewanimalsdata', 'Animal_usersController#viewAnimalData');
Route::get('/', 'AnimalController#index'); // just incase anything redricts to '/'
Route::resource('Animal', 'AnimalController');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Here is my .../public_html/.htaccess from my server.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
#Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /(~[^/]+)(.*)
RewriteRule ^ /%1/index.php [L]
</IfModule>
Thanks in advance
I have a blog folder in my servers /home/app/sites directory, and I have my laravel app in /home/app/public_html/laravel and my domain www.laravelapp.com is pointing to the project.
I want to point the url www.laravelapp.com/blog to my blog folder in /home/app/sites/blog.
How can I do that?
Here is my .htaccess file:
<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}]
# Redirect blog folder (Not working)
RewriteCond %{HTTP_HOST} ^www.laravelapp.com/blog$ [NC]
RewriteRule ^(.*)$ /home/app/sites/blog [L,R=301]
</IfModule>
../ goes one folder down
So it should be ../../sites/blog
There may be restrictions with htaccess. If this not already work share your .htaccess file. You cant go behind your base url, the following question explains it very well.
Having links relative to root?
Laravel is throwing a 404 error on my images, css and javascript files which are located in /mysite/public. I've set /mysite/public as the site's root folder and all my assets are located in there.
I did a google search on this error but they all gave the same solution i.e {{asset('css/style.css')}}. I already have my links setup like this so I don't think this is the problem.
I think the error has something to do with my Rewrite rules but I just can't figure our what it is.
My site's .htaccess file is:
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
</IfModule>
If I delete the first RewriteRule, my css loads fine but pages other that the homepage will start throwing a 404 error. If I put it back, other page work fine but css, js and image file stop loadings.
Your first rule essentially says "regardless of what the URL is, load index.php". This means it will never load your assets, which are physical folders, as it will just load index.php instead. For example, if you tried to load css/image.png it will just load index.php.
If you remove it, your actual folders will load, but other URLs aren't re-written to index.php, which is why it will break.
You should use the .htaccess provided to you by Laravel. This should be your .htaccess file in the public/ folder (as per the Laravel Github repository)
<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>
public/.htaccess
If the public folder is not the root on your server, you'll also need to have this in an additional .htaccess (in the folder above public)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
/.htaccess
add this rule to keep assets from being routed to the router
RewriteEngine On
# Don't rewrite for css/js/img assets
RewriteRule ^assets/.* - [L]
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
I want to remove the index.php from the url to access the controller action. Therefore I added the following code in my .htaccess file in the public/ folder:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I would be grateful if anyone reply me and solve this issues.
Why don't use the default Laravel .htaccess file. You should go fine with it.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
On my domain public directory is the laravel public directory.so there is index.php and htaccess file. but i want to access mydomain.com/demo/, where demo is a folder.its always redirect me to my home page as mydomain.com because of route rewrite . so how can i access folders in mydomain.com. my htaccess is followed. ...
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
thanks in advance
Create a separate .htaccess file within demo directory to override the .htaccess file in your root directory.
Order Allow,Deny
Allow from all
Create a separate .htaccess (as Brian Dillingham said) file within demo directory to override the .htaccess file in your root directory.
But put use codes below instead:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Also, you can refer the answer from: https://stackoverflow.com/a/38068912
For the ones out there who use a public domain but the Laravel directory is within a subdirectory. You might have the following folder structure:
- / <-- directory your domain (e.g. "https://example.com") points to
- some_subfolder1/
- some_subfolder2/
- laravel_project/
- ...
- public/
- .htaccess <-- File one has to modify
- index.php
- ...
The .htaccess File's RewriteRule for Front Controllers would look the following:
RewriteRule ^ laravel_project/public/index.php [L]
So you will end up with:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# 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 ^ laravel_project/public/index.php [L]
</IfModule>
In addition, I also modified the .env-File for the APP_URL param:
APP_URL=https://example.com/laravel_project/public
Furthermore, you might think of moving the laravel project files (despite from the public folder) outside of this file tree.