简体   繁体   English

Laravel .htaccess重写URL以删除公共

[英]Laravel .htaccess rewrite URL for removing public

I have a Laravel project 我有一个Laravel项目

My domain is domain.com.tw 我的域名是domain.com.tw

and the URL will be domain.com.tw/public , 网址为domain.com.tw/public

and the page could be showed. 并可以显示该页面。

I want to remove the public in URL, 我想删除网址中的public

so I write RewriteRule in .htaccess with: 所以我用.htaccess编写RewriteRule

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

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

but it did not work for me I had look at these also, but still failed 但是对我来说这没用,我也看过这些,但还是失败了

Apache Mod Rewrite For Laravel 适用于Laravel的Apache Mod Rewrite

Laravel 4.2 rewrite URL - remove public Laravel 4.2重写URL-删除公共

could someone tell me the solution? 有人可以告诉我解决方案吗? thanks!! 谢谢!!

Create a folder on root with named “whatever”(you can give any name). 在根目录上创建一个名为“ whatever”的文件夹(您可以输入任何名称)。 Move all files except public folder in the “whatever” folder. 将公用文件夹以外的所有文件移到“所有”文件夹中。 Move all the files of public to root directory and remove blank public folder. 将所有public的文件移动到根目录,并删除空白的public文件夹。 so directory structure will be: 因此目录结构为:

  1. whatever– which have all root files except public folder 随便-包含除公用文件夹之外的所有根文件
  2. all files of public folder. 公用文件夹的所有文件。

Now time to change some paths in paths.php change the following code 'public' => __DIR__.'/../public' , into 'public' => __DIR__.'/../../' , 现在该更改path.php中的某些路径了,将以下代码'public' => __DIR__.'/../public' 'public' => __DIR__.'/../../''public' => __DIR__.'/../../'

open index.php (on root) and find below code 打开index.php(在根目录下)并找到以下代码

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';

change this to 更改为

require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/start.php';

Hope this helps or at least give you some idea 希望这有助于或至少给您一些想法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM