Reputation: 1744
Quick question that I am sure someone can answer in about 2 seconds.
I have a Laravel project set up and one of the subdirectories is set up for documentation.
I have the following code set up.
Route::group(['prefix' => 'docs'], function(){
route::get('/', function(){
return redirect('docs.intro');
});
Route::get('/intro', ['as' => 'docs.intro', function(){ return view('docs.intro'); }]);
});
When I navigate to "www.site.com/docs/intro" all works fine. However, when I navigate to "www.site.com/docs/" it does not redirect like I was hoping, instead is throws a 403 "forbidden" error. Does anyone know why this is? How can I make this work properly?
Thanks!
Upvotes: 0
Views: 1166
Reputation: 552
If you are on apache, run apache2 -v
If it's Apache 2.4.x+
Options Indexes FollowSymLinks MultiViews
to Options +Indexes +FollowSymLinks +MultiViews
Change
Order allow,deny
Allow from all
to
Require all granted
Id it's not 2.4.X try this in htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
If you are using nginx :
sudo nano /etc/nginx/sites-available/default
Modify the server block to look like this
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public; **//Modify this according to your project**
index index.php index.html index.htm;
server_name server_domain_or_IP; **//Modify**
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo service nginx restart
Upvotes: 1
Reputation: 59
That's because you're pointing to a directory that exists, so your webserver is not forwarding the request to Laravel's index.php
file.
Check your apache / nginx configuration and look for the rewrite rules. If you're using apache, you'll probably find something like:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
That means that if the directory (-d
) or the file (-f
) exist, that rewrite won't happen.
Upvotes: 1