SEO, joomla and 2 domains for 2 languages - .htaccess

I’ve been looking around for the answer but I can't seem to find it. This is what I need:
www.domain1.it/en -> www.domain2.com/en
www.domain2.com/it -> www.domain1.it/it
I have tried a lot of possible solutions but no one works
RewriteCond %{HTTP_HOST} www.domain2.com
RewriteCond %{REQUEST_URI} ^/it/ [NC]
RewriteRule .* http://www.domain1.it/it [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_URI} ^/it/(.*)$
RewriteRule ^(.*)$ http://www.domain1.it/$1 [L,R=301]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/it/(.*)$
RewriteRule ^(.*)$ http://www.domain1.it/$1 [L,R=301]
It doesn’t work:
RewriteCond %{HTTP_HOST} www.domain2.com
RewriteCond %{REQUEST_URI} ^/it/
RewriteRule ^(.*)$ http://www.domain1.it/it/ [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com
RewriteCond %{REQUEST_URI} ^/it/
RewriteRule ^(.*)$ http://www.domain1.it/$1 [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteCond $1 !^en/$ [NC]
RewriteRule ^(.*)$ http://www.domain1.it/$1

I actually think some of your attempts would work, but your problem is probably your browser caching redirects making your debugging unreliable.
I think the following redirects are simpler and will do what you want.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteRule ^it(.*) http://www.domain1.it/it$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain1\.it$ [NC]
RewriteRule ^en(.*) http://www.domain2.com/en$1 [R=301,L]

Related

Problem HTACCESS: How to give priority absolute path?

We are busy with a name change for our webshop and i am working on our HTACCESS to redirect 1700 links. from those 1700 links there are 177 links that are changing in our new webshop. So they have to be in the HTACCESS. The other links keep the same and i redirect them now with a general rewriterule.
The only problem now is that he does not look well what the exact link is. For example see below my HTACCESS.
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/ [R=301,L]
RewriteCond %{HTTP_HOST} ^old.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]
When i type now the following url in the browser www.old.nl/vloerkleden/catagorie/vintage-vloerkleed/ he links me to www.new.nl/vloerkleden in stead of www.new.nl/vloerkleden/vintage-vloerkleed.
Your problem in this line :
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]
Nothig to present (.*)$ in substitution https://www.new.nl/vloerkleden/ so , it should look like this https://www.new.nl/vloerkleden/$1 because $1 will represent (.*) in pattern.
Also , you could do this with another rules and you could also sumerize your rules like this :
RewriteEngine on
# the folwoing rules will force every request for both old & new into https://wwww:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(?!.*www\.)(.*)$
RewriteRule .* https://www.%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]
Note: clear browser cache then test.

htaccess redirect only for one domain

I have several domains pointing to the same webspace (www.domain1.com, www.domain2.com, www.domain3.com, etc.). Only when one domain is used, e.g. www.domain1.com, I want to redirect users from different short link, e.g. www.domain1.com/link or www.domain1.com/link2, to another URL.
I have put together the following. The RewriteCond is probably ok but the RewriteRules doesn't work:
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^/test$ http://www.domain1.com/xyz.php [R=301]
RewriteRule ^/test2$ http://www.domain1.com/abc.php [R=301]
RewriteRule ^/test3$ http://www.domain1.com/abc/test10.php [L,R=301]
Do you have any tip how the correct RewriteRules should look like?
Hopefully this helps you get going in the right direction...
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/xyz.php [R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test2/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/abc.php [R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test3/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/abc/test10.php [L,R=301]

htaccess 301 redirect everything except /admin

I have been scratching my head for almost half an hour already because of this. I don't know what I am doing wrong, might just be under my nose, but i just cant see it. Here's what I have on my .htaccess
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
When I access example.com/admin, i am still redirected to newsite.com/admin.
Can anyone please advise? Thanks!
UPDATE: This is my everything that I have on mod_rewrite currently:
RewriteRule ^googleabcdef12345.html - [L]
RewriteCond %{HTTP_HOST} ^sample1\.no$ [NC]
RewriteRule ^(.*)$ http://www.newsample1.no/$1 [L,R=301]
RewriteCond %{HTTP_HOST} example\.com$ [NC]
#RewriteRule admin - [S=1]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
It is a drupal website btw. I tried QUERY_STRING instead of REQUEST_URI but no luck still.

ModRewrite canonical URLs in .htaccess file

I'm using ModRewrite to redirect URLs to their canonical ones in my .htaccess file. I've got something a bit like this:-
RewriteCond %{HTTP_HOST} ^www.ex\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.ex\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^ex\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
It works, but doesn't look pretty. Can I combine these conditions into a single rule?
You can link the conditions together by including an OR in the brackets, since the Rule that they are tied to are all the same:
RewriteCond %{HTTP_HOST} ^www.ex\.co\.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.ex\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^ex\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Rewrite rule for dynamic subdomain redirecting each file with subdomain arguments

I want to redirect all the calls to files in a subdomain with an extra variable. like if a user access www.domain.com/news.php and in the subdomain he accesses the same page then it should add an extra argument to the url like xyz.domain.com/news.php should be re written like it calls the file news.php?subdomain=xyz. Also i have other rules for just simple domain.
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /index.php?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?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]
The solution pointed to by adaptr at: https://serverfault.com/a/409171/128746 - would solve this problem very well.

Resources