Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

php - 没有index.php的路由不起作用(Routes not working without index.php)

Im using laravel 4. (我正在使用laravel 4。)

I have a view nest.blade.php and the corresponding controller NestController.php: (我有一个view nest.blade.php和相应的控制器NestController.php:)

Controller content: (控制器内容:)

class NestController extends BaseController {

    public function showView()
    {
        return View::make('nest');
    }

}

Route: (路线:)

Route::get('/nest', 'NestController@showView');

When I go to url/nest it doesnt work. (当我去网址/嵌套它不起作用。) When I go to url/index.php/nest it does work. (当我转到url / index.php / nest时,它确实起作用。)

Obviously I just want it to be /nest without the index.php. (显然,我只希望它不带index.php即可。)

How can i resolve this? (我该如何解决?)

My htaccess: (我的htaccess:)

IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
  ask by RSM translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Pretty URLs (漂亮的网址)

The framework ships with a public/.htaccess file that is used to allow URLs without index.php. (该框架附带一个public / .htaccess文件,该文件用于允许没有index.php的URL。) If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module . (如果您使用Apache服务Laravel应用程序,请确保启用mod_rewrite模块 。)

If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one: (如果Laravel随附的.htaccess文件不适用于您的Apache安装,请尝试以下操作:)

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

For more related help, check this answer . (如需更多相关帮助,请查看此答案 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...