我的laravel安装似乎有问题,当你输入domainname.com/laravel而不是显示目录时,我试图将url路由设置为公共文件夹。
然而,当我把
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
进入laravel目录中的.htaccess;它只是想出了这个。
请告诉我如何解决这个问题......因为我真的不知道。
答案 0 :(得分:2)
听起来你要做的就是在你网站的子目录中托管Laravel。大多数情况下,Laravel应用程序托管在网站的根目录中,即yourdomain.com
。但是,您希望Laravel应用程序显示在yourdomain.com/laravel
中。正确?首先,警告:
这不是托管Laravel应用的推荐方式
但是,如果你真的想把东西移到子目录中,这是你可以开始的一种方式。
public/
中创建子目录并在那里移动核心Laravel文件默认情况下,干净的Laravel安装在public/
文件夹中包含以下文件:
public/
- .htaccess
- favicon.ico
- index.php
- robots.txt
- web.config
创建一个子目录并将这些文件移入其中,例如如果您的子目录被调用laravel/
,那么您的新结构将如下所示:
public/
- laravel/
- .htaccess
- favicon.ico
- index.php
- robots.txt
- web.config
请务必不要更改Laravel附带的.htaccess
文件的内容。否则你的网站肯定不会工作。
index.php
以便它仍然可以找到Laravel核心在public/laravel/index.php
内,您需要更新所有类似的行:
require __DIR__.'/../bootstrap/autoload.php';
看起来像:
require __DIR__.'/../../bootstrap/autoload.php';
应该有两行需要更改。
此时,如果有人要访问yourdomain.com/laravel
他们会看到Laravel欢迎屏幕。您还可以按照app/Http/routes.php
范围内的方式创建路线。例如,如果您的路线文件如下所示:
Route::get('/', function () {
return view('welcome');
});
Route::get('/hiya', function() {
return 'hiya!';
});
然后访问yourdomain.com/laravel/hiya
的人会在屏幕上看到“hiya”这个词。
就像已经说过的那样,Laravel通常不打算从子目录运行,因此以我所描述的方式使用它可能会导致许多问题和意外行为。
但是,您仍然可以在public/
文件夹中托管静态文件,并按照您对任何网站的方式提供服务。
答案 1 :(得分:1)
当您将project
放在子目录中时,实际上不推荐放置laravel文件的方法,建议采取步骤正确放置directory
的内容。首先,保留安装时的.htaccess
。然后,您可以使用以下steps
来使您的网站正常运行。
1. You see `public` directory, copy all the contents of the it and `paste` it in your `root` directory and then remove the `public` folder from the original place.
2. then you make a single folder and put all the contents inside newly created folder except the contents of public folder that you just pasted in your root
在你的root之后你将拥有的结构就像
a) contents of public folder
b) a single folder, lets say `myproject` including all the contents except public
现在,您应该像
一样编辑index.php
require __DIR__.'/myproject/bootstrap/autoload.php';
$app = require_once __DIR__.'/myproject/bootstrap/app.php';
此处myproject
是您放置除public
目录内容之外的所有内容的文件夹名称
最后,清除所有cache
,您的计划应该有效
如果您仍希望.htaccess
参与您的工作,我建议您在论坛中进行一些搜索