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

.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 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法