How can I use "mod rewrite" to redirect the path to the subdomain, but without redirecting the browser?

I have a file that I want to redirect to a subdomain using mod_rewrite. For example, I would like to redirect a request for http://www.mydomain.com/xyzto a subdomainxyz.example.com

I do not want to send the redirect to the browser (so that it does not know that the page is different).

BTW. xyzis a CNAME record pointing towww.otherdomain.com.

Another example, just to clarify. If entered into the browser http://www.mydomain.com/xyz/something, I want Apache to return the contentshttp://xyz.mydomain.com/something

+3
source share
2 answers

I THINK that this will do what you want:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*?)/(.*?)$ http://$1.mydomain.com/$2

, , , css, , , ,

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(blog|store|other)/(.*?)$ http://$1.mydomain.com/$2

mydomain.com/blog/mydomain.com/store/ mydomain.com/other/

+2

, . :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^([^/]+)/(.*) /absolute/path/to/subdomains/$1/$2

, :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^([^/]+)/(.*) http://$1.example.com/$2 [P]

.htaccess. httpd.conf, RewriteRule /.

+1

Source: https://habr.com/ru/post/1703990/


All Articles