htaccess mod_rewrite hostname

.htaccess, apache, debian, mod-rewrite, redirect

Solution

Try adding these rules to the htaccess file in your document root:

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

Problem

How can i rewrite the domain url to a specific domain name if it didnt match it .. Let's say i want it to only match example.com and the visitor came from server ip (http://127.0.0.1/something/else) OR came from another domain (http://domain.com/something/else) how can i rewrite the domain name and keep all the other parameters, just domain name to example.com ( result should be : http://example.com/somthing/else )

Original source