Subdomains redirection in htaccess

Now for Login in my website i use only Social Media Websites. Like twitter,facebook,google and other.

The links thats i do looked like

RewriteRule ^login-google.*$ login_with_google.php [R=301,L]
RewriteRule ^login-vk.*$ login_with_vk.php [R=301,L]
RewriteRule ^login-twitter.*$ login_with_twitter.php [R=301,L]
RewriteRule ^login-yandex.*$ login_with_yandex.php [R=301,L]
RewriteRule ^login-mailru.*$ [R=301,L]

Now after i add subdomains in my website, to login with some of social websites, i get Error: redirect_uri_mismatch .

Now i need to do redirect like subdomains.
For example → redirect to → redirect to

How to do that ? thanks.

and this is all my login options
RewriteCond %{HTTP_HOST} ^(google|vk|twitter|yandex|ok|mailru)$ [NC]

No any one know ?

How to short this ? thanks

RewriteCond %{HTTP_HOST} ^google\.mysite\.com$ [NC]
RewriteRule (.*)$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^yandex\.mysite\.com$ [NC]
RewriteRule (.*)$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^vk\.mysite\.com$ [NC]
RewriteRule (.*)$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^twitter\.mysite\.com$ [NC]
RewriteRule (.*)$1 [R=301,L,QSA]
1 Like


I believe that you’ve not thought this through. What do you believe Apache will serve if is requested? From your code sample,!?!

I suspect that your login scripts don’t even need the “file request” to be passed to it as a key’s value but that’s one option … and I’ll bet that the QSA is of no value to those scripts, too!

You’re on the right track with your redirections except that the R=301 and QSA won’t help AND the $1 not being included IN the updated query string WILL disable your redirections (they are NOT part of any useful extension, are they?).

Once you get past all that, try something like:

RewriteEngine on RewriteCond %{HTTP_HOST} ^{google|yandex|vk|twitter)\.mysite\.com$ // The NC flag won't help as the SEs are in the login scripts which are case sensitive RewriteRule .?{REQUEST_URI} [L,QSA]

Note: It looks like the code is NOT being handled correctly by the new forum software but you should get the meaning.



1 Like


  1. first thank you!

  2. second I love your answers!


  1. You’re welcome
  2. :kissing: ?!?!?



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.