htaccess Rewriterule for Multilanguage Website - .htaccess

I have a Multilanguage-Website with 2 domains like www.domain.com and www.domain.de
Now I want to define some RewriteRules like:
RewriteRule ^category/(.*)$ http://www.domain.de/$1 [R=301,L]
But I dont know how I can change it to work for both domains at once. Changing that target just without the domain doesnt work.
Example:
RewriteRule ^category-[0-9]{1,4}/(.*) http://www.domain.de/category/$1 [R=301, L]
This would redirect the user to the .de-domain. Doesnt matter which domain he was on preview pages. So visitors from domain.com would be suddenly on domain.de on some specific pages with this rule.
I want this rule to work for both domains and dont know how to write the target path.

I found a solution.
RewriteBase /
and RewriteRule without domain

Related

HTACCES rewrite, just does not wat I want (preserve everything after the slash)

I have been trying different rewrite rules all day, but I just don`t cannot get it working in the way I want.
What I need:
http://www.example.com/page
to redirect to
http://example.com/page
Now, every rule I try, as soon as I add www. to my URL, it just redirects to the homepage, instead of the page I intended to visit.
I use Magento, maybe it is something with my settings within Magento?
PS. I tried several rules, including this one:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]

.htaccess with partially matching domain name

I have a really basic set of rewrite conditions in my .htaccess file, which doesn't work for one condition.
I have run it through a .htaccess tester which claims it should work, but it doesn't on the real site.
I have site.com, site.com.au, anothersite.com.au which should all redirect to site.com.au
RewriteBase /
# Domain Aliases
Rewritecond %{HTTP_HOST} !^www\.site\.com\.au$ [NC]
RewriteRule (.*) http://www.site.com.au/$1 [L,R=301]
When I visit anothersite.com.au, it 301s successfully to site.com.au, however when I visit site.com it just stays at site.com and doesn't 301. I have used ^ and $ which should limit the match to the exact .com.au domain but it still seems to just decide that .com is enough and doesn't redirect.
I have also tried using individual rules for all of the domains- this behaves in the same way.
Is anyone able to shed some light on this for me?

Redirecting all domain aliases to one with htaccess

I have a few domain aliases, while I only want one of them to be actually used.
At the moment, I have two domains installed,
To redirect I'd like to use htaccess.
My domains currently work like so:
www.domain.com/index.html - Main domain's home page
www.secondDomain.com/index.html - Displays exactly the same home page as the main domain, but I want it to automatically rename the url to www.domain.com/index.html when it's used.
Thanks!
It is a simple matter of matching %{HTTP_HOST} not equal to www.domain.com and redirecting that to the canonical domain.
RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]

301 redirect two domains pointing to the same IP - need to retain google rankings

I have two domains example.uk.net and example.co.uk - the example.uk.net has been in use since the website was started but i want to change over to the .co.uk version now - both domains are currently pointing to the same IP/sever - you see the same website on both domains...
Now i know i need to 301 redirect from the .uk.net to the .co.uk but i've read that it is best to do this page by page to retain google rankings/listings and also it is best practise anyway now i just can't seem to get this working as both domains point to the same site i can't use rewrite rules in the htaccess file such as...
Redirect 301 /get-a-quote/ http://example.co.uk/get-a-quote/
i also seem this piece of code on here that did seem to work but only for the main page, not any sub pages also it still doesn't work on a per page basis only redirecting the whole site...
RewriteCond %{HTTP_HOST} !^example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://example.co.uk$1 [R=301,L]
If anyone could help me out that would be brilliant or if someone has handled something similar in the past - any pointers would be awesome...
Thanks
You were missing a /:
RewriteCond %{HTTP_HOST} !^example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://example.co.uk/$1 [R=301,L]

htaccess redirect for subdomains -> similarly-named subdirectories?

I'm restructuring a web site with a great deal of content currently parked at URLs that look like this.
http://string.domain.com/year/month/dd/string-pulled-from-title
For various reasons, I'd like to park all new content at URLs that looks like this
http://www.domain.com/blogs/string/year/month/dd/string-pulled-from-title
I'd like to make the change for future content, but don't want all the old stuff to go 404.
I believe a 301 redirect rule in my htaccess will do the trick, sending all referred traffic coming in through old links to the new formats.
But what should this rule look like? I've read a few tutorials but haven't found this exact case in any examples.
Note, I don't want to do this for all subdomains, only for about 10 specific ones. So if someone could help me figure out one of these, then I can copy paste it 10 times in my htaccess for each subdomain and be set.
Drop this into the .htaccess file of the old site (adjusting the domain to your actual one):
RewriteEngine On
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]
This will grab this part of the URL at the old site:
year/month/dd/string-pulled-from-title
and redirect it to the new site under the new location:
blogs/string/year/month/dd/string-pulled-from-title
Alternatively, if you want something a little more variable like, without having to custom fix each .htaccess, drop this in the file for each subdomain instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
If you're redirecting to the same domain, and it includes the www, adjust the rewrite rules to the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
Note the second RewriteCond which checks to make sure that the URL requested does not include the leading www, which may lead to an endless redirect if the destination URL itself includes www and would try and redirect that subdomain as well.
%1 grabs the first capture group from the line above.
$1 references the first capture group on the same line.

Resources