Php 我不知道';我不想提供Laravel 5.1公共目录中的内容

Php 我不知道';我不想提供Laravel 5.1公共目录中的内容,php,apache,.htaccess,laravel,mod-rewrite,Php,Apache,.htaccess,Laravel,Mod Rewrite,我有一个larvel5.1项目运行得非常好。假设它的主机位于http://www.example.com。当我转到这个地址时,它工作得非常好,URL中没有所需的public/。现在唯一的问题是如果有人去http://www.example.com/public/很明显,他看到的主页内容没有加载任何CSS和JS,这对SEO完全没有好处,因为这将被视为重复的站点。我尝试过在互联网上搜索,但每个人都在回答如何从URL中删除public/,但就我而言,它已经被删除了。我只是不想让用户看到public/中

我有一个
larvel5.1
项目运行得非常好。假设它的主机位于
http://www.example.com
。当我转到这个
地址
时,它工作得非常好,URL中没有所需的
public/
。现在唯一的问题是如果有人去
http://www.example.com/public/
很明显,他看到的主页内容没有加载任何CSS和JS,这对SEO完全没有好处,因为这将被视为重复的站点。我尝试过在互联网上搜索,但每个人都在回答如何从URL中删除
public/
,但就我而言,它已经被删除了。我只是不想让用户看到
public/
中的内容,如果他明确地去了那里。有没有办法做到这一点?我将把我的
.htaccess
文件也张贴在这里。它得到了许多代码,用于启用缓存、添加
www.
和域。请帮我解决这个问题。我完全卡住了。 这是我的
.htaccess
文件内容

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf .ttf
    AddType application/x-font-opentype .otf
    AddType application/x-font-woff .woff
    AddType image/svg+xml .svg
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    # Add a far future Expires header for fonts
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-opentype "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresDefault "access plus 1 week"
    </IfModule>
    ## EXPIRES CACHING ##

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

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

选项-多视图
##过期缓存##
AddType应用程序/vnd.ms-fontobject.eot
AddType应用程序/x-font-ttf.ttf
AddType应用程序/x-font-opentype.otf
AddType应用程序/x-font-woff.woff
AddType image/svg+xml.svg
过期于
过期按类型映像/jpg“访问加1年”
过期按类型图像/jpeg“访问加1年”
ExpiresByType image/gif“访问加1年”
过期按类型图像/png“访问加1年”
ExpiresByType文本/css“访问加1个月”
过期按类型应用程序/pdf“访问加1个月”
ExpiresByType text/x-javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
过期按类型图像/x图标“访问加1年”
#为字体添加“远未来过期”标题
ExpiresByType应用程序/vnd.ms-fontobject“访问加1年”
按类型应用程序到期/x-font-ttf“访问加1年”
过期按类型应用程序/x-font-opentype“访问加1年”
过期按类型应用程序/x-font-woff“访问加1年”
ExpiresByType图像/svg+xml“访问加1年”
ExpiresDefault“访问加1周”
##过期缓存##
重新启动发动机
重写cond%{HTTP_HOST}^www\。
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[R=301,L]
#如果不是文件夹,则重定向尾部斜杠。。。
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]

在根目录下创建.htaccess页面,包含以下内容

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

选项-多视图
重新启动发动机
#重定向尾部斜杠。。。
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]

我认为这是一个懒惰的设计决策,允许所有目录和文件都成为入口点。WordPress也做同样的事情。您可以这样修复它:

# Handle Front Controller...
RewriteCond $0 =public [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]* index.php [L]

这应该忽略目录检查,只检查
/public/
,而保持其他功能不变。

最后一条规则基本上是一个无限前缀循环,仅通过
限制内部递归停止。
。谢谢@Walf。它就像一个符咒。帮了我很多。我想我应该多学点ApacheDoc;-)ApacheDocs非常出色,但将一般概念应用于特定问题确实需要实践。