我正在我的Hostgator共享主机上设置Laravel,我对如何在我的网站上解析链接有一个问题。
我遵循了一个简单的教程,了解如何在Laravel中创建链接,而不需要生成更多实际的.php文件,但访问这些链接的方法我必须使用www.samplewebsite.com/index.php/contact
我该如何将我的.htaccess设置为www.samplewebsite.com/contact.php链接?
-更新--
我的目录结构如下:
/ -包含我的php、perl5、etc和public_html文件夹的laravel安装。
我的Laravel安装结构如下:
公用文件夹为/app_base/public/的/app_base/。
我在我的public_html (www)文件夹中创建了一个Demo文件夹,作为我的测试环境,所以在开始创建合适的网站之前,我已经掌握了开发过程。
/public_html/DEMO
-index.php-
<?php
/**
* Laravel - A
PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
require __DIR__.'/../../app_base/bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
require __DIR__.'/../../app_base/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);我的public_html文件夹中包含我的.htaccess文件。如下所示:
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
RewriteCond %{HTTP_HOST} ^spotoncreative\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.spotoncreative\.net$
RewriteRule ^default\.html$ "http\:\/\/www\.spotoncreative\.net\/Splash\/" [R=301]
RewriteCond %{HTTP_HOST} ^spotoncreative\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.spotoncreative\.net$
RewriteRule ^/?$ "http\:\/\/www\.spotoncreative\.net\/Splash\/" [R=301]我希望这会有更多的帮助。
发布于 2015-04-28 00:12:41
使用/public文件夹中的Laravel .htaccess。
https://github.com/laravel/laravel/blob/master/public/.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>发布于 2015-04-28 00:15:30
对站点的所有查询都需要转到/public/index.php文件。index.php文件将触发Laravel启动并遍历您的路由。如果您在路由文件中定义了路由'/contact‘,那么www.samplewebsite.com/contact将路由到您指定的任何位置。据我所知,最佳实践是将应用程序放在根文件夹之外,然后在重定向到应用程序的/public/index.php的路由中放置一个别名,该应用程序位于您的服务器上。这样,当您推送新代码时,您可以首先推送代码,然后在一切正常运行后更改别名。如果你需要回滚,这也会变得更容易。
我不太擅长调整Apache服务器,我更喜欢使用Heroku这样的东西,在那里我可以在Procfile中放置一个webroot到/public/index.php。如果您刚刚开始使用Laravel,并且我上面所说的没有太多意义,我建议您使用Heroku root,它在开发规模上是免费的。
这里有一个关于使用Laravel MySql/PHP栈部署到Heroku的很好的教程:https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku
https://stackoverflow.com/questions/29900251
复制相似问题