php - htaccess redirect TLD preserve subdomains -


i want redirect tlds specific tld, , want preserve subdomains.

the followings redirect examples need:

sub1.domain.net -> sub1.domain.com sub2.domain.net -> sub2.domain.com sub3.domain.net -> sub3.domain.com  sub1.domain.org -> sub1.domain.com sub2.domain.org -> sub2.domain.com sub3.domain.org -> sub3.domain.com 

i have tried code in .htacess file:

rewritecond %{http_host} !^([a-za-z_\-\.(0-9)]*)domain\.com rewriterule  ^ http://$1domain.com%{request_uri} [l,r=301] 

but $1 not recognized variable.

$1 undefined in example not capturing uri. use captured part of hostaname ,you need %n variable. :

rewritecond %{http_host} !example\.com$ rewritecond %{http_host} ^((?!www\.).+)\..+$ rewriterule ^ http://%1.example.com%{request_uri} [ne,l,r] 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -