laravel 去掉index.php伪静态

时间:2022-02-27 20:00:18

1,首先,让apache服务器支持rewrite  

    可以在apache配置文件中定义rewrite规则,是全局的,无论哪个应用都实用

    //httpd.config

        Listen 80

        RewriteEngine on   ---将rewrite开启

        LoadModule rewrite_module modules/mod_rewrite.so  前面的注释去掉

        在Directory中配置:

        <Directory "/www/poem/public">

            Options Indexes FollowSymLinks

            AllowOverride All        ----这项一定要进行修改

            Order deny,allow

            Allow from all

        </Directory>

2,配置.htaccess文件  ---find / -name .htaccess 来查找此文件

    <IfModule mod_rewrite.c>

        Options +FollowSymLinks

        RewriteEngine On

    </IfModule>

    <IfModule mod_rewrite.c>

        RewriteCond %{REQUEST_FILENAME} !-f

        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule ^(.*)$ index.php/$1 [L]    ---这句话的含义是:任何访问网站的路径都映射成index.php/xxx,其中xxx是$1 与 (.*)中的内容进行匹配  例如我们输入http://192.168.0.222/about  -->http://192.168.0.222/index.php/about

    </IfModule>

3,如果是专门针对laravel进行配置,则在app/app.php中加入

    index=>'',   //laravel4.1中没有此项,直接手写加入即可

 

 

如果还不行

先在httpd.conf注释掉

#<Directory />
#   Options FollowSymLinks
#    AllowOverride All
#    Order deny,allow
#    Deny from all
#</Directory>

然后在httpd-vhost修改如下,

<VirtualHost *:80>
    ServerAdmin none@none.com
    DocumentRoot "E:/www/learnlaravel5/public"
    ServerName le
    DirectoryIndex index.php index.html
    ErrorLog "logs/dummy-host.2012-20090214YX.domain-error.log"
    CustomLog "logs/dummy-host.2012-20090214YX.domain-access.log" common
    <Directory "E:/www/learnlaravel5/public">
        Options -Indexes +FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
        #Require all granted
    </Directory>
</VirtualHost>