John Davidson

javascript - Laravel project is calling the wrong paths

0 comments
Message:


I am new to Laravel and I am testing out an application that i have made. locally it works fine but when I push it to a server, then the routing seems to go really bad. Usually a path to a view would be like 156.0.125.1/app/index, but it keeps looking for 156.0.125.1/index which gives the error of URL not found on server


I suspect its the .htaccess file but I'm not too sure what to change there as I'm not familiar with it.


also the css and the js seem to not be read by the site on the server


heres the htaccess


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

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]

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

# Disable Directory listing
Options -Indexes

# block files which needs to be hidden, specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
Order allow,deny
Deny from all
</Files>


My Answer:
You can try modifying your .htaccess file to include the correct base path for your Laravel project. Here is an example of what you can add to your .htaccess file:



RewriteEngine On
RewriteBase /app/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /app/index.php [L]



This will set the base path for your Laravel project to /app/. Make sure to replace /app/ with the actual path to your project if it is different.

As for the issue with CSS and JS files not being read, make sure that the paths to these files in your HTML templates are correct. You may need to update the paths to point to the correct location on the server. For example, if your CSS file is located at /app/css/style.css, make sure your HTML template includes it like this:





This should help resolve the issues with routing and file paths on your server.

Rate this post

3 of 5 based on 6507 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us