Htaccess 301 only part of the redirect works - apache

Hi Im moving a site from one domain to another, and I have created the following .htaccess file, but its not working.
*#Options +FollowSymlinks
RewriteEngine On
redirect 301 http://www.el-netshop.dk/pi/Dækkape_UG150_12_lysegrå_5302_.aspx http://www.el-netsalg.dk/pi/Dækkape_UG150_12_lysegrå_5271_.aspx
RewriteCond %{HTTP_HOST} ^el-netshop.dk$ [OR]
RewriteCond %{HTTP_HOST} ^www.el-netshop.dk$
RewriteRule (.)$ http://www.el-netsalg.dk/$1 [R=301,L]
I would like it to work like this.
Have a list of urls where the url is diffent, with more then just the domain. Ex. in the above the from link contains 5302 but to link is 5271.
Then with the rest, I want it to make a normal redirect.
The above code just do (.*)$ http://www.el-netsalg.dk/$1 and ignores the special cases.
What am I doing wrong?

According to the apache docu the syntax is as folows:
Redirect 301 /service http://foo2.bar.com/service
So try:
Redirect 301 /pi/Dækkape_UG150_12_lysegrå_5302_.aspx http://www.el-netsalg.dk/pi/Dækkape_UG150_12_lysegrå_5271_.aspx
without the "http://www.el-netshop.dk" for the old-path paramater.

Related

Redirect 301 except when a string is present in url with htaccess

I would like to redirect a subdirectory to a subdomain, but i have to maintenance the endpoints for sitemaps.
What I need is:
Redirect 301 /ru/ https://ru.mydomain.com
#Exclude *sitemap*
This kind of urls can't be redirected:
https://www.mydomain/ru/sitemap.xml
https://www.mydomain/ru/sitemap.1.xml
https://www.mydomain/ru/sitemap.3.xml
https://www.mydomain/ru/sitemap_ru.xml
All have sitemap string and i need no be redirected when sitemap word is in url.
Hope can help me, as i take many time trying to fix it without luck.
I need like:
{if *sitemap* is not present}
Redirect 301 /ru/ https://ru.mydomain.com
{/if}
Thanks!
This one should work for you. If the URL on your website (www.mydomain) starts with /ru but not with /ru/sitemap... we redirect (301) to https://ru.mydomain.com/ but without the /ru in the path. e.g. https://www.mydomain/ru/news goes to https://ru.mydomain.com/news
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mydomain$ [NC]
RewriteCond %{REQUEST_URI} ^/?ru(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/?ru/sitemap.*$ [NC]
RewriteRule ^/?ru(/(.*))?$ https://ru.mydomain.com/$2 [R=301,L]
The NC Flag means that this is case insensitive.
You need mod_rewrite installed end enabled!

htaccess - Redirecting all traffic to another domain except existing 301's

My htaccess file is filled with 301 redirects like such:
Redirect 301 /old-page.html https://www.example.com/new-page
There are about 100 of these redirects. What I would like to do is redirect all traffic going to the old site to go to the new site excluding the existing 301's
So if someone goes to old-site.com/old-page.html it will take them to new-site.com/new-page and if someone goes to old-site.com/random-page.html it will take them to new-site.com - just the home page.
Is it possible to do this using mod_rewrite and mod_alias without rewriting the current 301's?
You can keep all your 301 rules. Just insert this generic 301 rule below your existing rule:
# all existing 301 rules go here
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?old-site\.com$ [NC]
RewriteRule ^ http://new-site.com/? [L,R=301]
You need to use a RewriteCond in front of all your rules like this:
RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
If you want all the following rules to be processed as well DO NOT use the L (last) flag in the RewriteCond statement.
Source: Redirect all urls exactly, just change domain name

Error when redirecting a domain

The thing is I have one domain in different languages, and I´m not able to do some redirects like this:
I have Spanish http://www.domain.es/inicio
And English http://www.domain.en/inicio
Now, I need to move my page http://www.domain.en/inicio to http://www.domain.en/home
Both domains are using the same .htaccess and I´m not able to do a simple:
Redirect 301 /inicio http://www.domain.en/home
Cause that will redirect the spanish /inicio to /home too.
Also tested
RewriteCond %{HTTP_HOST} ^www.domain.en/inicio/$ [NC]
RewriteRule ^(.*)$ http://www.domain.en/home/ [R=301,L]
But thats also failing.
Did you try something like this?
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /inicio/
RewriteRule ^inicio/(.*) /home/$1 [L,R=301]
You should redirect the content of the folder /inicio to folder /home if I got it right. There is no need to redirect everything since the domain is the same
The request should be GET since the users are accessing your website pages

Redirect with htaccess for images onto another server without redirect looping

I currently have a host where my main site is hosted on. I have set up nginx on another server to mirror/cache files being requested if it doesn't have it already, in particular images and flv videos.
For example:
www.domain.com is my main site.
www.domain.com/video/video.flv
www.domain.com/images/1.png
I would like to ask apache to redirect it to imgserv.domain.com (imgserv.domain.com points to another server IP)
imgserv.domain.com/video/video.flv
imgserv.domain.com/images/1.png
Basically redirect everything with certain filetypes and preserving the structure of the URL, like flv etc.
I tried something but I am getting a redirect looping error. Could someone help me out?
Thank you!
This is what I have at the moment
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RedirectMatch 302 ^(.*)\.gif$ http://imgserv.domain.com/forums$1.gif
RedirectMatch 302 ^(.*)\.jpg$ http://imgserv.domain.com/forums$1.jpg
RedirectMatch 302 ^(.*)\.png$ http://imgserv.domain.com/forums$1.png
You are mixing up two different modules: RewriteEngine and RewriteCond are from mod_rewrite while RedirectMatch is from mod_alias. They can’t work together.
Try this mod_rewrite example instead:
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*\.(gif|jpg|png)$ http://imgserv.example.com/forums/$0 [L,R]

301 redirect .htaccess

Im trying to request the following entire site 301 redirect:
word.something.blah.domain.com --> http://www.word.com
I don't know how to write the 301 redirect rule.
Can someone help out?
I will assume you are using the same directory to serve files on both domains. In which case, a Redirect clause won't work (infinite redirect loop).
With mod_rewrite, you can check the value of the current HTTP_HOST and take a decision based on that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.something\.blah\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.%1.com/$1 [R=301,NE,L]
put this into root directory of the subdomain:
Redirect permanent / http://www.word.com
If you are keeping everything else the same - that is, the file names - but simply changing the domain, this code is all you need to put on the OLD DOMAIN htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]