【问题标题】:laravel 5.4 removing public form url not working properlylaravel 5.4 删除公共表单 url 无法正常工作
【发布时间】:2018-03-29 08:00:16
【问题描述】:

我已将 server.php 文件重命名为 index.php 并添加 .htaccess 代码如下

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

RewriteEngine On

# 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>

url 现在工作正常,没有 url 也可以工作,但是

asset()
public_path()

功能无法正常工作。 css、js、图片调用不正确。

{{ asset('assets/css/custom.css') }}

以上所有 custom.css 的代码都不起作用,之前它工作正常。 如果我添加 public 比它正常工作,但这是不正确的方式。

{{ asset('public/assets/css/custom.css') }}

让我知道如何将 public 全局添加到这些函数中。

我也尝试使用此引用删除 url,但它不起作用。 How can I remove “public/index.php” in the url generated laravel?

【问题讨论】:

  • 这是共享主机帐户还是您的本地主机?
  • 我想你这样做是因为你在共享主机上,否则你应该在 Laravel 应用程序的文件夹中将主机的根文件夹设置为 /public。但是,如果您在共享主机上,为什么不只是符号链接到公用文件夹,如下所示:ln -s /laravel-app/public /public_html

标签: php laravel .htaccess laravel-5 laravel-5.4


【解决方案1】:

我做了三件事来解决这个问题。

我把这个htaccess 文件放在我的项目根文件夹中

<IfModule mod_rewrite.c>
     RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

还有我公用文件夹中的这个.htaccess配置,也就是project-folder/public

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

    RewriteEngine On
    # 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]
</IfModule>

然后将我的虚拟主机配置定义为

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/path/projectfolder/public"
    <Directory  "/path/projectfolder/public">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require All
    </Directory>
</VirtualHost> 

这解决了我的问题

【讨论】:

    猜你喜欢
    • 2019-03-30
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2015-06-09
    • 2019-03-12
    相关资源
    最近更新 更多