i have several domains (same name, but different endings) for the different languages. the .com domain is the main domain and has for each language a directory like /en/
now i want to redirect each of these domains ( e.g. http://example.us/ ) to http://example.com/en/
is this possible with the .htaccess file?
actual i only have a redirection from www.example.com to http://example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
You can do it this way
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} \.(at|ch)$ [NC]
RewriteRule ^(.*)$ http://example.com/de/$1 [L,R=301]
RewriteCond %{HTTP_HOST} \.us$ [NC]
RewriteRule ^(.*)$ http://example.com/en/$1 [L,R=301]
RewriteCond %{HTTP_HOST} \.fr$ [NC]
RewriteRule ^(.*)$ http://example.com/fr/$1 [L,R=301]
But if you have more domains (maybe a lot) you could use RewriteMap
Related
There are 10 different domains names. I would like to redirect some of them to:
somedomain1.com, somedomain2.com -> somenewdomainONE.com/en
somedomain3.com, somedomain4.com -> somenewdomainTWO2.com/fr
I have tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?somedomain1.com$ [NC, OR]
RewriteCond %{HTTP_HOST} ^(www.)?somedomain2.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomainONE.com/en [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?somedomain3.com$ [NC, OR]
RewriteCond %{HTTP_HOST} ^(www.)?somedomain4.com$ [NC]
RewriteRule ^(.*)$ http://www.somenewdomainTWO.com/fr [L,R=301]
I'm not sure why, but this redirects all domains to http://www.newdomainONE.com/en even when I try accessing somedomain3 or somedomain4.com. I'm also getting a redirect loop depending on what I try.
You can just use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomainONE.com/en/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?(domain3|domain4)\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomainTWO.com/fr/$1 [L,R=301]
Make sure to test in a new browser to avoid old 301 cache.
My domain "example.com" is redirected to the "www.example.com".
and the for each it's subdomain "www.subdomain.example.com" is redirected to the "subdomain.example.com" and linked to a root subfolder "example.com/admin". So far so good.
The issue here is when I access to "/admin" for the domain itself i wanted to redirect to "www.example.com/admin" but subdomain to "subdomain.example.com/admin" .
this is my .htaccess file in /admin:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.([^\.]*)\.example\.com$ [NC]
RewriteRule (.*) http://%1.example.com$1 [R=301,L]
Any way I can do this? Much appreciated.
You can do like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com$ [NC]
RewriteRule ^((?!admin).*)$ http://%1.example.com/$1 [R=301,L]
Let's say may main domain is www.mysite.com and that I'm using the following rewrite in my hataccess
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
All good so far! However, I also need other domains to redirect to specific pages on the site. For example, if somebody types www.mysite.nl they will be redirected to www.mysite.com/neatherlands. The issue is when I pop the below into my htaccess file I get a server error. I think this is because of the final rewrite. It's a pretty mad set-up
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.nl$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/netherlands/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.be$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/belgium/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co.\uk$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
Any suggestions about what to do?
My domain www.abc.com is now redirecting to https://www.abc.co.uk
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
These code works exactly what I want. After that I created a subdomain. www.x.abc.co.uk
Now I want to redirect that to http://x.abc.co.uk (without https)
I used this
RewriteCond %{HTTP_HOST} ^x\.abc\.co\.uk [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But browser says it has redirect loop.
How can do that?
If these are two different htaccess files then give this a try.
RewriteEngine On
#redirect www.x.abc.co.uk without www to http
RewriteCond %{HTTP_HOST} ^www\.x\.abc\.co\.uk [NC]
RewriteRule ^(.*)$ http://x.abc.co.uk%{REQUEST_URI} [L,R=301]
I modified your original rule so you don't have two rewrite rules and still direct to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.abc.co.uk%{REQUEST_URI} [L,R=301]
I have set up virtual subdomain. and i want to make htaccess to achive the following flow
For
www.domain.com
it should call the index file but for the subdomain
abc.domain.com
The rewrite rule should be like
RewriteRule www.domain.com/index.php?var=abc
i mean it should (in HTACCESS) pass the subdomain to the index file as an argument
and for the Other file requests like
abc.domain.com/file.php
The subdomain should be rewritten like www.domain.com/file.php?var=abc
I mean the Rewrite rule like
RewriteRule www.domain.com/file.php?var=abc
This would be how you could do them on an individual basis.
RewriteCond %{HTTP_HOST} ^abc\.domain\.com$ [NC]
RewriteRule (.*)$ http://www.domain.com/file.php?var=abc [L]
RewriteCond %{HTTP_HOST} ^def\.domain\.com$ [NC]
RewriteRule (.*)$ http://www.domain.com/file.php?var=def [L]
The solution is something like this
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.domain.com/index.php?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?%{QUERY_STRING}&subdomain=%1 [L]