dongxiangxie8181 2015-12-27 14:45
浏览 53
已采纳

设置子域 - AWS和Laravel

I'm slowly migrating my website into the artisan era using Laravel. I have it setup on AWS on a vanilla Amazon linux.

Currently I have; www.example.co.uk blog.example.co.uk careers.example.co.uk

These are all on the same server and the subdomains have been achieved using htaccess to redirect to \blog and \careers folders in my root with DNS being handled by Route 53

Now in moving to laravel it only considers the public folder (htaccess use no longer required apart from the default one it comes with) so I have my DocumentRoot as /var/www/example/public. Everything works great! Setup a bunch of routes for my main site and still smooth sailing.

Now moving to the subdomains, I have the below in my hhtpd.conf

<VirtualHost *:80>
  ServerName blog.example.co.uk
  ServerAdmin webmaster@blog.example.co.uk

  DocumentRoot /var/www/example/public

  <Directory /var/www/example/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

  ErrorLog /var/log/blog.example.co.uk.error.log
  LogLevel warn
  CustomLog /var/log/blog.example.co.uk.access.log combined
</VirtualHost>

As you can see I'm pointing the subdomain to the same public folder since Laravel should be able to see that blog.example.co.uk was requested and perform its duties to route correctly.

I have the below routes for the subdomain

Route::group(['domain' => 'blog.example.co.uk'], function () {

    Route::get('/', 'BlogController@home')->name('blog-home');
    Route::get('review', 'BlogController@review')->name('blog-review');
    Route::get('author/{id}', 'BlogController@author')->name('blog-author')->middleware('blogGuard');
    Route::get('category/{id}', 'BlogController@category')->name('blog-category')->middleware('blogGuard');
    Route::get('post/{id}', 'BlogController@post')->name('blog-post')->middleware('blogGuard');
    Route::get('press', 'BlogController@press')->name('blog-press');
    Route::get('about', 'BlogController@about')->name('blog-about');

});

Unfortunately, going to blog.example.co.uk still assumes that I requested www.example.co.uk and routes using the logic for the main site. So blog.example points to www.example.

I have also used '{blog}.example.co.uk'

What am I doing wrong please Cheers!

  • 写回答

1条回答 默认 最新

  • dongyan3853 2016-01-04 15:25
    关注

    It looks like this is an issue with the order of operations of your routes, where it matches a route before it even reaches the subdomain route group. You should put everything into its own route group and that should solve the problem. As an alternative you could make sure your non-grouped routes are below your grouped routes and that might also solve the problem.

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

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并