【问题标题】:remove Public Url . htaccess laravel 5.5删除公共网址。 htaccess laravel 5.5
【发布时间】:2018-04-20 20:22:25
【问题描述】:

从我搜索的 url 中删除 public/ 并尝试按照这些步骤操作

  1. 从 public/ 复制 .​​htaccess 并将其粘贴到 root /
  2. 将 server.php 更改为 index.php

  3. 我试试哟添加

    重写引擎开启 RewriteRule ^(.*)$ public/$1 [L]

到我的 /.htaccess 删除 url public 它没有工作。

但如果我删除那行它可以工作,但我所有的 URL 链接到 css 都是错误的路径

NOTE :: I PUT all my Css into public/assets if I move folder assets  to my / It work but is their anyway If I dont want to move my floder assets

更新.htaccess

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

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

【问题讨论】:

标签: laravel laravel-5.5


【解决方案1】:

您可以通过 2 种可能的方式做到这一点:

(1) 将你的 Laravel 根文件夹中的 server.php 重命名为 index.php 将 .htaccess 文件从 /public 目录复制到你的 Laravel 根文件夹。对于静态文件,您可以更改 htaccess 文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

(2) 不需要对 htaccess 做任何事情。

1) copy index.php in public folder. remove/rename index.php in public.

2) paste in root folder of the project

3) Now open index.php and change 2 url paths like below. 
   require __DIR__.'/vendor/autoload.php';
   $app = require_once __DIR__.'/bootstrap/app.php';

就是这样:)

这样你需要更改js和css文件路径,在这些路径中添加/public/。

【讨论】:

    猜你喜欢
    • 2015-07-17
    • 2020-08-13
    • 2016-12-02
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 2015-06-09
    相关资源
    最近更新 更多