URI переписать на поддомен - PullRequest
0 голосов
/ 31 августа 2018

Я пытаюсь изменить URI на поддомен. как изменить www.domain.com/auth/signin на login.domain.com

У меня есть виртуальный хост, как этот:

<VirtualHost 127.0.0.5:80>
   DocumentRoot "path/to/root/public"
   ServerName domain.local
   ServerAlias *.domain.local
</VirtualHost>

и .htaccess

RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

RewriteCond %{HTTP_HOST} !^domain.local
RewriteCond %{HTTP_HOST} ^(.+).domain.local
RewriteRule ^login/?$ http://domain.local/auth/signin [P,L,QSA]

1 Ответ

0 голосов
/ 01 сентября 2018

1: Стандартная версия http:

RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

# If the url is not http://domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^domain\.local [NC]

# If the url is not http://www.domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^www\.domain\.local [NC]

# Redirect
RewriteRule ^login(.*)$ http://domain.local/auth/signin$1 [R=301,L,NC]

http://sub1.domain.local/login до http://domain.local/auth/signin

http://sub2.domain.local/login до http://domain.local/auth/signin

http://sub2.domain.local/login?token=1 до http://domain.local/auth/signin?token=1

2: (необязательно) обнаружение http или https

RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

# If the url is not http(s)://domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^domain\.local [NC]

# If the url is not http(s)://www.domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^www\.domain\.local [NC]

# http or https detection
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS}:s on:(s) 

# Redirect
RewriteRule ^login(.*)$ http%1://domain.local/auth/signin$1 [R=301,L,NC]

http://sub1.domain.local/login до http://domain.local/auth/signin

https://sub1.domain.local/login до https://domain.local/auth/signin

http://sub2.domain.local/login до http://domain.local/auth/signin

https://sub2.domain.local/login до https://domain.local/auth/signin

http://sub2.domain.local/login?token=1 до http://domain.local/auth/signin?token=1

https://sub2.domain.local/login?token=1 до https://domain.local/auth/signin?token=1

...