Htaccess for subdomain not working

Hi!

Yesterday I add redirection to my subdomain from https://m.xxx.com to https: //www.m.xxx.com
then my subdomain cannot be access, the error occured “The page isn’t redirecting properly”
Here is my htaccess

RewriteCond %{HTTP_HOST} ^m\.xxx\.com
RewriteRule ^m/assets/(.*)$ m/web/assets/$1 [L]
RewriteRule ^m/css/(.*)$ m/web/css/$1 [L]
RewriteRule ^m/js/(.*)$ m/web/js/$1 [L]	
RewriteRule ^m(/.*)?$ m/web/$1 [L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} m.xxx.com$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This is my subdomain config main

<?php
use kartik\datecontrol\Module;
use yii\web\Request;

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

if((new Request)->getBaseUrl() == '/web')
{
	$baseUrl = str_replace('/web', '', (new Request)->getBaseUrl());
}
else
{
	$baseUrl = str_replace('/m/web', '/mobile', (new Request)->getBaseUrl());
}

return [
    'id' => 'app-mobile',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log', 'devicedetect', 'assetsAutoCompress'],
    'controllerNamespace' => 'mobile\controllers',
    'modules' => [
		'user' => [			
			'as mobile' => 'dektrium\user\filters\FrontendFilter',
		],		
	],
    'components' => [		
		'user' => [
			'identityCookie' => [
				'name'     => '_mobileIdentity',
				'path'     => '/',
				'httpOnly' => true,
			],
		],
		'session' => [
			'name' => 'MOBILESESSID',
			'cookieParams' => [
				'httpOnly' => true,
				'path'     => '/',
			],
		],		
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],	
		'request' => [
            'baseUrl' => $baseUrl,
			'class' => 'common\components\Request',
			'web'=> '/m/web',	
        ],
        'urlManager' => [
			'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
				'' => 'site/index',                                
				'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',	
			]			
        ],
		'assetManager' =>
			[
				'appendTimestamp'   => true,						
			],
		'geoip' => ['class' => 'lysenkobv\GeoIP\GeoIP'],
		'devicedetect' => ['class' => 'alexandernst\devicedetect\DeviceDetect'],
		'assetsAutoCompress' =>
			[
				'class'         => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
				'enabled' => true,

				'readFileTimeout' => 3,           //Time in seconds for reading each asset file

				'jsCompress'                => true,        //Enable minification js in html code
				'jsCompressFlaggedComments' => true,        //Cut comments during processing js
				'cssCompress' => true,        //Enable minification css in html code

				'cssFileCompile'        => true,        //Turning association css files
				'cssFileRemouteCompile' => false,       //Trying to get css files to which the specified path as the remote file, skchat him to her.
				'cssFileCompress'       => true,        //Enable compression and processing before being stored in the css file
				'cssFileBottom'         => false,       //Moving down the page css files
				'cssFileBottomLoadOnJs' => false,       //Transfer css file down the page and uploading them using js

				'jsFileCompile'                 => true,        //Turning association js files
				'jsFileRemouteCompile'          => false,       //Trying to get a js files to which the specified path as the remote file, skchat him to her.
				'jsFileCompress'                => true,        //Enable compression and processing js before saving a file
				'jsFileCompressFlaggedComments' => true,        //Cut comments during processing js

				'noIncludeJsFilesOnPjax' => true,        //Do not connect the js files when all pjax requests						
				'htmlFormatter' => [
					'class' => 'skeeks\yii2\assetsAuto\formatters\html\MrclayHtmlCompressor',
				],						
			],
        'view' => [
            'class' => '\ogheo\htmlcompress\View',
        ],	
    ],
	'modules' => [
	   'datecontrol' =>  [
			'class' => '\kartik\datecontrol\Module'
		]
	],
    'params' => $params,
	'homeUrl' => '/xxx/mobile',
];

Before I add redirection in my hosting, subdomain can access well
but now it cannot be access.

Please help

Hi,

Could you do the redirection at the vhost level instead? It would be 10000 times easier:

<VirtualHost *:443>
    ServerName m.xxx.com

    SSLEngine On
    # your ssl certificate directives for m.xxx.com

    RedirectPermanent / https://www.m.xxx.com/
</VirtualHost>

This would involve no PHP, no Yii, no rewrites … :slight_smile: