dpnru86024 2015-06-23 15:25
浏览 47
已采纳

.htaccess子域重写在Laravel中

I have a Laravel install that is using the standard .htaccess file, which works great for dev.mysite.com but on my dev server I have foo.dev.mysite.com and another route which is bar.dev.mysite.com

The routing is working fine, but the requests are not being rewritten to index.php, for example when I go to foo.dev.mysite.com/example I get a 404 but when I go to foo.dev.mysite.com/index.php?example it's working fine.

I have the following .htaccess file:

<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条回答 默认 最新

  • dongyejun1983 2015-06-23 17:21
    关注

    First, make sure mode_rewrite is enabled. I am sure you have probably done this but I want to make sure nothing is missed. Another test is to remove the IfModule condition and see if it fails.

    Next, see what version of apache you are running since the syntax has changed between 2.2 and 2.4. The Optons default was changed from All to FollowSymlinks in 2.3.11. This should not be a big deal and doubt this is the culprit but could be and save you trouble in the future.

    Next, try putting the rewrite condition inside of the vhost information instead of the htaccess file. This can help a little with performance as well as give you a console warn/err when restarting apache where the htaccess errors could be squelched.

    <directory /var/www/mysite.com>
        Options -MultiViews
        AllowOverride ALL
        RewriteEngine On
    
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </directory>
    

    Beyond this point I would be at a loss without some more logging or information from the server. You can also add CustomLog into the vhost and report all requests processed by the server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?