I'm developing my 2nd Laravel app on my local machine. The first one has no issues with the url (it can use index.php or not) but my second one throws a 404 if I don't use index.php.
I copied the apache conf file and edited in the url so it is identical to the original in all other aspects. Apache mod rewrite is enabled (the other site works without index.php)
The only difference is that the new site is in laravel 8 whereas my working other laravel app is using laravel 7
.htaccess is the standard laravel file. My conf files are using the public folder in both instances. So why is this different? Have I missed something obvoius?
thanks
Craig
*** EDIT *** @Brian Thompson: This is on a dev machine apache permissions have been added to my user so can just use {USER} As requested here is some code (let me know if you need more than my project.conf and .htaccess files): .htaccess in {doc_root)/public (unchanged from when created and identical to the one from Laravel7)
<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>
and my apache conf file (which is a copy of the working one with the server names and document roots changed)
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin [email protected]
ServerName laravel2.tst
DocumentRoot /var/www/laravel2.tst/htdocs/public
<Directory /var/www/laravel2.tst/htdocs/public>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog /var/www/laravel2.tst/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerName laravel2.tst
ServerAlias laravel2.bup
ServerAdmin [email protected]
DocumentRoot /var/www/laravel2.tst/htdocs/public
ErrorLog /var/www/laravel2.tst/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I can confirm that the paths are correct (i put my dev projects in a htdocs folder and with laravel I extend this to the public folder)
*** EDIT2 *** Here is my web.php files contents
<?php
use App\Http\Controllers\AccountController;
use Illuminate\Support\Facades\Route;
/*
|
All routes work correctly except i have to use index.php in the url (ie https://laravel2.tst/index.php or https://laravel2.tst/index.php/accounts/5/edit) this is causing issues with links in the app in that i have to use /index.php/{rest of link}
Finally after struggling with this for 2 weeks with no help I found a solution to this which hopefully will help others facing this same scenario. Nothing of a mention of this in the docs and nobody here seemed to be able to help.
First I added an Alias in the apache conf file for this item
Alias /laravel2.tst /var/www/laravel2.tst/htdocs/public/
I then edited the .htaccess in the public folder by adding the following immediately afterRewriteEngine On
RewriteBase /laravel2.tst
Then after restarting apache my urls are fixed and no longer require index.php to be in them to work. I'd say thanks for the help but...
Interestingly on the laravel 7 instance this wasn't needed and isn't configured. So no idea if this is actually needed, is the right way to do this or if there is another way which is better.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.