I have a domain, www.example.com and subdomain test.example.com. When i call test.example.com i need to redirect this to www.example.com/search/property/test_state without changing the url from test.example.com. so the url should look like test.example.com only.
I did this with the .htaccess code like,
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^$ /search/property/%1_state [P]
Now after this when i access any urls from the subdomain like test.example.com/content/sell_your_home it should not change the url to main domain. currently when i access this it is redirecting to main domain. any ideas?
If the test subdomain has the same server root (document root) as the main domain, then you don't need the P
flag:
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule ^$ /search/property/%1_state/ [L]
Otherwise, you need the full URL:
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule ^$ http://www.example.com/search/property/%1_state/$1 [L,P]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [L,P]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.