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.

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

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件