【发布时间】:2018-03-01 13:39:09
【问题描述】:
我正在我的 Hostgator 共享虚拟主机上设置 Laravel,但我对如何在我的网站上解析链接有疑问。
我正在学习如何在 Laravel 中创建链接而不需要生成更多实际的 .php 文件的简单教程,但访问这些链接的方法我必须做www.samplewebsite.com/index.php/contact
如何将我的 .htaccess 设置为该链接变为 www.samplewebsite.com/contact.php?
-- 更新--
我的目录结构如下:
/
- 这包含我的 laravel 安装作为我的 php、perl5、etc 和我的 public_html 文件夹。
我的 Laravel 安装结构如下:
/app_base/,公用文件夹为/app_base/public/。
我在我的 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);
我的 .htaccess 文件包含在我的 public_html 文件夹中。如下:
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]
我希望这会有所帮助。
【问题讨论】:
-
尝试使用.htaccess并设置目录索引httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
-
这些对我没有任何作用,只是给我同样的 500 内部服务器错误。我将发布我的目录结构以及我如何设置我的 laravel 站点的更新。