Redirect one domain to another in .htaccess - .htaccess

I am looking to one domain to another with all sub-urls as well. The original url would be ehanceinsdev.com and the redirected url would be www.enhanceinsurance.com. I would want it so that enhanceinsdev.com/foo would go to www.enhanceinsurance.com/foo.
Thanks for your help!

You can use this simple rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^enhanceinsdev\.wpengine\.com$ [NC]
RewriteRule ^ http://www.enhanceinsurance.com%{REQUEST_URI} [R=301,L,NE]

Try
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^ehanceinsdev\.com$ [NC]
RewriteRule ^(.*)$ http://www.enhanceinsurance.com/$1 [R=301,L]

Related

Redirect with htaccess if url of multiple subdomain not contains directory

And I have a lot of subdomain:
sub1.abc.com, sub2.abc.com,.., subn.abc.com with the same directory: true-dir-1, true-dir-2, true-dir-3
I want to
If url not contains (true-dir-1, true-dir-2, true-dir-3) then redirect to subdomain
For example:
sub1.abc.com/false-dir redirect to sub1.abc.com
sub2.abc.com/false-dir redirect to sub2.abc.com
Pls help me use .htaccess to redirect it..
Thanks so much!
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.abc\.com$ [NC]
RewriteRule !^true-dir-1 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub2\.abc\.com$ [NC]
RewriteRule !^true-dir-2 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub3\.abc\.com$ [NC]
RewriteRule !^true-dir-3 / [L,NC,R=302]
You can use that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.abc\.com$ [NC]
RewriteRule !^%1 / [L,NC,R=302]
Change [R=302] for [R=301] when test work well.

htaccess 301 redirect query to new domain

trying to redirect this query to a new domain:
www.domain.com/search.php?q=keyword
to
www.newdomain.com/search.php?q=keyword
keyword can be any word
And want to keep the rest in domain, I just need to redirect this query.
I try several ways and the one I found closer to solution is this one:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=1$
RewriteRule ^search\.php$ http://www.newdomain.com/search.php?q=$1 [R=301,L]
but does not work!
Hope someone could help me correcting this and also if this is the best way to do the job?
Many thanks.
You're pretty close.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^(search\.php)$ http://www.newdomain.com/$1 [R=301,L,NC]
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]
this works and is simple
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [QSA]

.htaccess rewrite multiple urls without redirects

Ok so i have urls like these demo1.domain.net, demo2.domain.net, demo3.domain.net and all needs to show the contents of a subfolder like this example
demo1.domain.net will show the contents of domain.net/websites/demo1
i need to do it in a way that all the domains like $whatever.domain.net into domain.net/websites/$whatever.domain.net, i already enabled wildcard dns, and i cant seem to fiqure it out, please keep in mind i dont want it to redirect.
Here is what i tried
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.domain\.net.*$
RewriteRule /websites/$1 [L]
I just get the main page of domain.net with this.
Your help will be greatly appreciated.
Close, try this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/websites/
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+\.domain\.net.*)$ [NC]
RewriteRule ^(.*)$ /websites/%2/$1 [L]
Note that this will only work if the all the demo*.domain.net point to the same document root as the main domain (domain.net).
I think, I can manage this! Could you please try these .htaccess directives AGAIN:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.net$
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.domain\.net$
RewriteRule ^/?$ http://domain.net/websites/%2 [P]
It will rewrite $whatever.domain.net into domain.net/websites/$whatever.
NOW if it's suppose to be $whatever.domain.net into domain.net/websites/$whatever.domain.net then you could try this one:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.net$
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.domain\.net$
RewriteRule ^/?$ http://domain.net/websites/%2.domain.net [P]
Or maybe this code below is what you've wanted in the future:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.net$
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.domain\.net$
RewriteRule ^(.*)$ http://domain.net/websites/%2.domain.net/$1 [P]

.htaccess domain language redirect to folders

I have this situation:
When somebody goes to www.example.com, it should display www.example.com/en/
When somebody goes to www.example.fr, it should display www.example.com/fr/
Can you help me with htaccess setup?
Thank you guys!
Simple solution for .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www.example.fr$ [NC]
RewriteRule ^$ http://www.example.com/fr/ [L,R=301]
RewriteCond %{HTTP_HOST} www.example.com$ [NC]
RewriteRule ^$ http://www.example.com/en/ [L,R=301]

redirect one domain to another with htaccess rules

I was wondering how i can redirect my users from my old domain to a new url
forexample
http://www.5.joblessbuddy.com/news.html
into this
http://www.1.joblessbuddy.hu/news.html
i did this on my htaccess but not working
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} http://www.5.joblessbuddy.com/$ [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu$1 [R=301,L]
any suggestion would be appreciated
thanks in advance
Try this:
RewriteCond %{HTTP_HOST} (www\.)?5\.joblessbuddy\.com [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu/$1 [R=301,L]
btw: mod_rewrite cheat sheet v2 is your friend.

Resources