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.*$ login_with_mail.ru.php [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

http://facebook.mywebsite.com → redirect to http://mywebsite.com/login_with_google.php
http://twitter.mywebsite.com → redirect to http://mywebsite.com/login_with_twitter.php

How to do that ? thanks.

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

No any one know ?

How to short this ? thanks

RewriteCond %{HTTP_HOST} ^google\.mysite\.com$ [NC]
RewriteRule (.*) http://mysite.com/login_with_google.php$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^yandex\.mysite\.com$ [NC]
RewriteRule (.*) http://mysite.com/login_with_yandex.php$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^vk\.mysite\.com$ [NC]
RewriteRule (.*) http://mysite.com/login_with_vk.php$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} ^twitter\.mysite\.com$ [NC]
RewriteRule (.*) http://mysite.com/login_with_twitter.php$1 [R=301,L,QSA]
1 Like

A_S,

I believe that you’ve not thought this through. What do you believe Apache will serve if http://google.mysite.com/lotza_garbage is requested? From your code sample, http://mysite.com/login_with_google.phplotza_garbage!?!

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 .? http://mysite.com/login_with_%1.php?request=%{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.

Regards,

DK

1 Like

dklynn

  1. first thank you!

  2. second I love your answers!

A_S,

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

Regards,

DK

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