2015-12-27 14:45 阅读 52

设置子域 - 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;

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>

  DocumentRoot /var/www/example/public

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

  ErrorLog /var/log/
  LogLevel warn
  CustomLog /var/log/ combined

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

I have the below routes for the subdomain

Route::group(['domain' => ''], 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 still assumes that I requested and routes using the logic for the main site. So blog.example points to www.example.

I have also used '{blog}'

What am I doing wrong please Cheers!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongyan3853 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.

    点赞 评论 复制链接分享