: Configure clean URLs for Laravel using a rewrite rule to index.php Recently I've started learning Laravel , I have none experience with framework before. I'm encountering the following problem
Recently I've started learning Laravel , I have none experience with framework before. I'm encountering the following problem .I'm trying to configure the .htaccess file so I can have clean URLs but the only thing I get are 404 Not Found error pages. I have created a virtual host - you can see below the configuration file - and changed the .htaccesss file on the public directory.
/etc/apache2/sites-available
<VirtualHost *:80>
ServerAdmin admin@laravel.lar
ServerName laravel.lar
DocumentRoot "/home/giannis/Desktop/laravel/public"
<Directory "/home/giannis/Desktop/laravel/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
.htaccesss file:
laravel/public
# Apache configuration file
# httpd.apache.org/docs/current/mod/quickreference.html
# Note: ".htaccess" files are an overhead for each request. This logic should
# be placed in your Apache config whenever possible.
# httpd.apache.org/docs/current/howto/htaccess.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
In order to test it, I have created a view named about and made the proper routing. If I link to laravel.lar/index.php/about/ I'm routing to the about page instead if I link to laravel.lar/about/ I get a 404 Not Found error.
I'm using a Debian based system.
More posts by @Lengel546
2 Comments
Sorted by latest first Latest Oldest Best
I met the same problem today. I solved it in two steps
Enabling of rewrite module
sudo a2enmod rewrite
I changed AllowOverride None to AllowOverride All in my virtual host configuration file. AllowOverride None - prevents Apache server from reading of any .htaccess file located in your site directories.
Hope it helps.
I think I see your problem. You are adding an extra question mark in your rewrite rule.
RewriteRule ^(.*)$ index.php?/ [L]
Should be
RewriteRule ^(.*)$ index.php/ [L]
based on the example urls your provide. laravel.lar/index.php/about/ doesn't have a question mark in it after index.php
It is also possible that mod_rewrite is not enabled. It looks like you are an a Debian based system such Ubuntu. You can use the command sudo a2enmod rewrite to enable mod_rewrite.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.