I want to redirect requests on abc.com to abc.jp by adding this line to .htaccess file
RewriteRule ^(.*)abc\.com(.*)$ $1abc.jp$2
But it didn't work. So confusing...
Try using RewriteCond to match the domain, then redirect using RewriteRule
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?abc.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://abc.jp$1 [NC,L,R=301]
Related
I have several domains pointed to my hosting. Suppose I have ex1.com, ex2.com, ex3.com pointed to my hosting. Now ex2.com is hosted on another hosting. Now I want to add a redirect rule on the htaccess file so that I can redirect ex1.com to ex2.com. What will be the code? I tried the code below but no luck :-
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.ex1.com [NC]
RewriteRule ^(.*)$ http://www.ex2.com/$1 [L,R=301,NC]
Can anyone please inform me what I have to do?
You require Redirect 301:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
This is useful when you use www.newdomain.com as your new domain name. If the domain is different, then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
Obviously replace olddomain and newdomain with the correct domains.
What should I put in .htaccess to redirect all links from main domain to subdomain? I have it like that but it doesnt wok:
RewriteCond %{HTTP_HOST} ^http://example.com/$
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L]
Have you tried without the http:// and the / at the end in the first line ?
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L]
here is what I do and works good:
#redirect subdomains to controller
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^([a-zA-Z0-9-_]*)$ blog.php?blog_uid=%1 [L,QSA]
now I want to redirect
http://example.domain.com/post-123.html
to
blog.php?blog_id=example&post_id=123
but this not works:
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^([a-zA-Z0-9-_]*)/post-([0-9]+)\.html$ blog.php?blog_uid=%1&post_id=%2 [L,QSA]
how do it? actually how redirect such subdomain request to a rewrite condition (it is not a real page).
Use this rule instead:
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^post-([0-9]+)\.html$ /blog.php?blog_id=%1&post_id=$1 [NC,L,QSA]
Try this one.
RewriteEngine On
RewriteRule ^post-([^/]*)\.html$ /blog.php?blog_id=example&post_id=$1 [L]
I am stuck on the follow htaccess situation.
I want to redirect pages to subdomains.
Url example right now;
http://domain.tld/user/foo
I need to redirect this to;
http://foo.domain.tld
The subdomain is genereated by wildcard.
I tried the follow without succes;
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.tld [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld?$
RewriteRule (.*) s/index.php?user=%1 [NC,QSA]
RewriteRule ^user/(.*) (.*) [R=301,L]
Regards,
Nick
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.tld [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld?$
RewriteRule (.*) s/index.php?user=%1 [NC,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.tld [NC]
RewriteRule ^user/([a-zA-Z0-9-.]+) http://$1.domain.tld/ [R=301,L]
I'm trying to do something like this...
Redirect www.mysite.com/directory/* to my subdommain.mysite.com/directory/*
Please help me
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^directory/(.*)$ http://subdommain.mysite.com/directory/$1 [R=301,L]
I want like it
Try adding this to your .htaccess file if you want to redirect all requests from www.mysite.com to subdomain.mysite.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://subdomain.mysite.com/$1 [R=301,L]
Try adding this to your .htaccess file if you want to redirect only requests for /anydirectory/ from www.mysite.com/anydirectory/ to subdomain.mysite.com/anyotherdirectory/:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^anydirectory/(.*)$ http://subdommain.mysite.com/anyotherdirectory/$1 [R=301,L]