I'm making a link to a controller's function resides in a sub directory of Controller directory named 'Admin'. When I make a link in the menu bar using following code:
{!! HTML::link('/admin', 'Admin') !!} // www.property.com/admin
it doesn't work, but if I prefix '/admin' with 'index.php/admin' like this:
{!! HTML::link('index.php/admin', 'Admin') !!} // www.property.com/index.php/admin
it works fine. What is the problem? How can I get rid off adding 'index.php' before each of my link like 'admini'? Note I'm using virtual host named 'www.property.com' on Ubuntu 15.04. here is my AdminController ```
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return view('admin.index');
}
?>
Here is my route file
Route::resource('/', 'HomeController');
Route::resource('/admin', 'Admin\AdminController');
Here is the .htaccess file's code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Here is virtual host file code:
<VirtualHost *:80>
ServerAdmin m.khuramj@live.com
ServerName laravelproperty.com
ServerAlias www.laravelproperty.com
DocumentRoot /var/www/property-project/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If you are using Apache, make sure the .htaccess in your public folder is there.
If this is not the case, create a .htaccess in the public folder with the following content:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
If it's still not working, make sure the mod_rewrite module in Apache is enabled :).
After spending hours, I've found the solution of this problem. Though a miner one but took a lot of time.
In my virtual host file add the the following code like given below:
<Directory /var/www/property-project/public/>
AllowOverride All
</Directory>
you can compare the difference between this one and the code for virtual host give in the question above.
<VirtualHost *:80>
ServerAdmin m.khuramj@live.com
ServerName laravelproperty.com
ServerAlias www.laravelproperty.com
DocumentRoot /var/www/property-project/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/property-project/public/>
AllowOverride All
</Directory>
</VirtualHost>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.