I want to redirect feedback.domain.de to www.domain.de/de/abc/cde.html via htaccess.
My current htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.de$
RewriteRule ^(.*)$ http://www.domain.de/$1 [L,R=301]
SO, I thought just to add:
redirect 301 feedback.domain.de www.domain.de/de/abc/cde.html
but it doesn't work. If i try to open feedback.domain.de it redirects to www.domain.de
I know this is a very easy question but I don't how solve it in htaccess :-(
The result I want is:
domain.de -> www.domain.de/de/index.html
www.domain.de -> www.domain.de/de/index.html
domain.de/de/example.html -> www.domain.de/de/example.html
etc...
feedback.domain.de -> www.domain.de/de/feed.html
Best regards
The Redirect directive only accept a path relative to the root path (for example /my-path) and won't match on the host part of the URL.
Try this (note that here I assume you want to redirect domain.de to www.domain.de and not all subdomains):
RewriteEngine On
# Redirect feedback.domain.de to http://www.domain.de/de/abc/cde.html
RewriteCond %{HTTP_HOST} ^feedback\.domain\.de$
RewriteRule . http://www.domain.de/de/abc/cde.html [L,R=301]
# Redirect domain.de to www.domain.de
RewriteCond %{HTTP_HOST} ^domain\.de$
RewriteRule . http://www.domain.de/$0 [L,R=301]
Updated answer (2013-03-18):
# Redirect feedback.domain.de to http://www.domain.de/de/abc/cde.html
RewriteCond %{HTTP_HOST} ^feedback\.(domain\.(de))$
RewriteRule .+ http://www.%1/%2/feed.html [L,R=301]
# domain.de -> www.domain.de/de
RewriteCond %{HTTP_HOST} ^(domain\.(de))$
RewriteRule .+ http://www.%1/%2/$0 [L,R=301]
# www.domain.de/de -> www.domain.de/de/index.html
RewriteCond %{HTTP_HOST} ^www\.domain\.(de)$
RewriteRule ^%1/?$ index.html [L,R=301]
Related
I have a website, let's say www.example.com but this used to be www.example.nl. All traffic from www.example.nl is now redirected to www.example.com, but as we changed some naming conventions, www.example.nl/seeds now has to redirect to www.example.com/nl/flower-seeds.
The .htaccess file I got contains the following code:
RewriteEngine On
RewriteBase
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
When I navigate to www.example.nl/seeds/ I end up at www.example.com/seeds/ which ends up in a 404 because I'm missing the /nl/flower- part.
I think Redirect doesn't work properly when the URL is already altered by a RewriteRule. How would you tackle this problem? Any help is appreciated!
You should exclude /seeds/ directory form general rules like this :
RewriteEngine On
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteCond %{REQUEST_URI} !/seeds/(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^seeds/(.*)$ http://www.example.com/nl/flower-seeds/$1 [L, R=301]
Note: clear browser cache then test
Also , don't use regex with redirect like what you did :
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
Here this (.*) has no meaning , you could use either RedirectMatch or RewriteRule
I have two domains:
newdomain.com
and
olddomain.com
I need to redirect all links from olddomain.com to the main page of newdomain.com so it should look like this:
olddomain.com/irrelevantDir1/irrelevantPage1.html -> newdomain.com
olddomain.com/irrelevantDir11/irrelevantPage11.html -> newdomain.com
But there are some links that i want to save:
olddomain.com/relevantDir1/relevantPage1.html -> newdomain.com/newRelevantDir1/newRelevantPage1.html
olddomain.com/relevantDir11/relevantPage11.html -> newdomain.com/newRelevantDir11/newRelevantPage11.html
I already spent two days tried to make RewriteRule but with no luck, i can really use some help here.
You can write your rules from specific to general case handling like this:
RewriteEngine On
# specific URL redirect 1
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^relevantDir1/relevantPage1\.html$ http://newdomain.com/newRelevantDir1/newRelevantPage1.html [NC,L,R=301]
# specific URL redirect 2
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^relevantDir11/relevantPage11\.html$ http://newdomain.com/newRelevantDir11/newRelevantPage11.html [NC,L,R=301]
# generic case
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com/ [L,R=301]
I have a subdomain called es and I need when someone wants to enter mysite.com/es it can be redirect to es.mysite.com. It works with the following htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://es.mysite.com/$1 [R=301,L]
RedirectMatch permanent ^/es/?$ http://es.mysite.com/$1
The problem is when someone types mysite.com/es/bla/bla/bla. In this case, with the current configuration on my htaccess, the user isn't redirected and I want the user can be redirected.
For example:
If I enter:
http://letsbonus.com/es/barcelona/spa-experiencie-para-2-opcion-masaje-desconecta-roc-nature-273710
This is redirect to:
http://es.letsbonus.com/barcelona/spa-experiencie-para-2-opcion-masaje-desconecta-roc-nature-273710
Thanks in advance.
You need just this one rule in your root .htaccess of mysite.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?(mysite\.com)$ [NC]
RewriteRule ^es/(.*)$ http://es.%1/$1 [R=301,L,NE]
Your two rules enter into conflict:
Base url: http://example.com/es/test
Non-www redirection -> http://www.example.com/es/test
es subdomain redirection -> http://es.example.com/test
Non-www redirection... (we're no longer under www subdomain)
I would use this htaccess to get the excepted result:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|es).example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^es/(.*)$ http://es.example.com/$1 [R=301,L]
I have two domains that point to the same webserver:
example.cz
example.de
I need:
example.de → example.de/de (but can't be see in address field: example.cz/de)
If it ends up showing in the URL like example.de/de it's OK, but the best solution is just example.de and from server load example.de/de.
I've tried with this:
RewriteBase /
RewriteCond %{HTTP_HOST} example.de$ [NC]
RewriteRule ^$ example.de/de [L,R=301]
but after I click on something on the page I get: example.cz/de and this is problem.
You can use an inner rewrite without R=301 redirect, if you use LAMP server, in /.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?example\.de$ [NC]
RewriteRule ^$ /de/index.php [L]
You'll see in address bar: http://example.de but not http://example.de/de .
Add this to redirect http://example.cz/de to http://example.de .
RewriteCond %{HTTP_HOST} (www\.)?example\.cz$ [NC]
RewriteRule ^de$ http://example.de [R=301,L]
So basically I want everyone who asks example.com/index.php to get 301 redirected to example.com/,
everyone who asks for any www. urls to get 301 redirected to corresponding non-www site
(www.examle.com/foo -> example.com/foo)
and everyone who asks for site with double [also triple etc.] slashes in url to get 301
redirected to url with double slashes remowed (example.com////foo -> example.com).
And if anyone should do any combination of these three cases, he should still get 301 redirected to right url (www.example.com////index.php -> example.com).
So I come up with that:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,N]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^(.*)$ /$1 [R=301]
BUT, www.example.com//foo -> http://example.com/http:/example.com/foo = 404!
How to get it working?
Try these lines :
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301]
RewriteRule ^index.php$ / [L,QSA,R=301]
RewriteRule ^(.*)/{2,}(.*)$ /$1/$2 [L,N,QSA,R=301]
Screw logic, seriously...
I found out, that folloving stuff in .htaccess does proper (almoust, with little quirks) 301 redirects to right places...
RewriteBase /
RewriteEngine on
...at the top, and the rewrite rules themselves:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301]
RewriteRule ^index\.php$ / [QSA,R=301]
I swear that these are only rewrite rules in my .htaccess.
The quirk is, that www.example.com//foo redirects(301) to example.com/foo, and then example.com/foo redirects(301) again to example.com/foo, bot only once... (no loops)
www.example.com//foo -> example.com/foo -> example.com/foo
Also when www and any other condition is met, redirection happens in steps:
www.example.com/index.php -> example.com/index.php -> example.com/
www.example.com//index.php -> example.com/index.php -> example.com/
But that's not really big problem...