Configure clean URLs using Laravel using a rewrite rule to index.php
Posted
by
yannis hristofakis
on Pro Webmasters
See other posts from Pro Webmasters
or by yannis hristofakis
Published on 2013-05-29T19:04:11Z
Indexed on
2013/07/03
11:19 UTC
Read the original article
Hit count: 592
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 [email protected]
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
# http://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.
# http://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?/$1 [L]
</IfModule>
In order to test it, I have created a view named about
and made the proper routing. If I link to http://laravel.lar/index.php/about/
I'm routing to the about
page instead if I link to http://laravel.lar/about/
I get a 404 Not Found
error.
I'm using a Debian based system.
© Pro Webmasters or respective owner