简体   繁体   中英

htaccess non existing subdomain to main domain redirection

Need to know if this possible or not? If yes then how?

Main Domain is: abc.com ; Subdomain is: sub.abc.com

I want to redirect everything like [alphanumeric].abc.com to abc.com except the sub domain ( sub.abc.com ).

eg ajf43vsfvsuvfsg.abc.com to abc.com ; "ajfvsfvsuvfsg" doesn't exist.

Try putting these rules in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(sub\.)?abc.com$ [NC]
RewriteRule ^(.*)$ http://abc.com/$1 [L,R]

If someone types http://blah.abc.com/some/path in their browser's URL address bar, they'll get redirected to http://abc.com/some/path and the address in the address bar changes.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM