2015-10-10 56 views
0

在Laravel使用Apache 2.4 4.2,如果我在网站根目录,然后公共路径访问的index.php不同的index.php设置错误。例如,/site/index.php返回的html文档是正确的,但是它的所有资产路径都是相对于/site。例如,Laravel设置错误的公共路径与子目录的index.php文件要求

文件系统路径:/var/www/htdocs/imgs/logo.png

正确的网址:/imgs/logo.png

真实路径:/网站/imgs/logo.png

发现此问题是因为旧网站在/site/index.php中有索引文件,并被搜索引擎编入索引。然后,当网站显示在搜索结果中时,它会显示到site/index.php的链接,并且所有资产路径都已损坏。

资产的路径设定Laravel的功能HTML::styleassets

我如何重定向所有的子路径,以的index.php在根文件里面的的index.php文件,除了这最后?

回答

0

默认Laravel 4.2的.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> 

然后我以前#Handle Front Controller

# Redirect to index.php if other index.php distict to the index.php is requested. 
RewriteCond %{REQUEST_URI} ((.+)/)+index.php [NC] 
RewriteRule ^/[R=301] 

添加新重写规则所以,我重定向(永久)站点根目录到子目录中的任何index.php