Reassign www to non-www in Laravel with URL parameters

How to redirect url from www.myapp.coto myapp.co? And also, if the URL has a different parameter, for example www.myapp.co/other-parameter, it will be redirected to myapp.co/other-parameterwhere it other-parametercan be any. Sorry for this noob question, I'm still 1 week in using Laravel.

By the way, I use a dynamic subdomain, so I only need to redirect www to non-www, and not to other subdomains.

Route::group(array('domain' => 'myapp.co'), function() {

    Route::get('/', function() {
        return 'Hello! Welcome to main page...';
    });
    Route::get('/login', function() {
        return 'Login';
    });
    Route::get('/signup', function() {
        return 'Signup';
    });

});

Route::group(array('domain' => '{account}.myapp.co'), function() {

    Route::get('/', function($account) {

        if ($account == 'www') {
            return Redirect::to('http://myapp.co');
        }
        return $account;
    });

});
+4
source share
4 answers

Perhaps you can use .htaccess inside the public folder for redirection.

Here is one of them:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} !localhost
    RewriteCond %{HTTP_HOST} !^(.+)\.(.+)\.(.+)
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
</IfModule>

, , , (form abc.xyz.tldn) www. , . , .

: : www wwww htaccess htaccess. ( )

+9

, , filter.php:

App::before(function($request){
   //Remove the 'www.' from all domains
   if (substr($request->header('host'), 0, 4) === 'www.') {
      $request->headers->set('host', 'myapp.co');
      return Redirect::to($request->path());
   }
});

, , , "www". "www.".

+11

fooobar.com/questions/51336/... , , nginx

# Force WWW:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
+1

www www URL

, URL- URL- www

- www non www

www non www urls .htaccess

  • zila
  • .htaccess
  • .htaccess

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
    
  • .htaccess
  • Check it out live
-2
source

All Articles