htaccess subpage on subdomain to subpage on other subdomain - apache

I have trouble finding out the right approach to make a 301 redirect from one subdomains page to another subdomains page.
For instance:
subpage1.mysite.com/contact
needs to be redirected to
subpage2.mysite.com/kontakt
(i have a few hundred of these)
I have a lot of 301 redirects in my .htaccess so far, but they only redirect from the maindomain mysite.com/page.
I cant make a 301 like this, right?
It does not work..
301
Redirect 301 http://subpage1.mysite.com/contact http://subpage2.mysite.com/kontakt
I only can access the primary htaccess file on the main domain (mysite.com)
Read some about RewriteCond but it seems they take all of my subpages and redirect them to the other subdomain. That is not exactly suitable for me, as the url's have changed names and are not identical on the subdomains.

I've figured it out by using this.
Taking the subdomain as RewriteCond
#Consultancy redirects
RewriteCond %{HTTP_HOST} ^consultancy.madebydelta.com [nc]
RewriteRule ^about/$ http://testlab.madebydelta.com/om-os/ [R=301,NC,L]
RewriteRule ^industries/$ http://testlab.madebydelta.com/cases/ [R=301,NC,L]

Related

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

htaccess redirect How to redirect subfolder to subdomain and subfolder

I moved a portion of the site to a subdomain. All answers I find here are without keeping the folder structure in mind.
So
http://mywebsite.com/projects
Has become
http://topic.mywebsite.com/projects
So what I have now is:
RedirectMatch 301 ^/projects/(.*)$ http://topic.mywebsite.com/projects/$1
But this creates an infinite loop.
So I tried
RedirectMatch 301 http://mywebsite.com/projects/(.*)$ http://topic.mywebsite.com/projects/$1
So it does not get into a loop on the subdomain, but this does not work at all.
Any idea?
You can use mod_rewrite and check that it only runs for the main site.
RewriteCond %{HTTP_HOST} =mywebsite.com
RewriteRule ^projects/(.*)$ http://topic.mywebsite.com/projects/$1 [R=301,L]

htaccess redirect on a domain that already redirects

We have 3 domains in play here. Domain1.com is the main site, domain2.com is the smaller second site, and domain3.com is a vanity URL that redirects from domain1 to a Spanish version of domain2.
What we need to have happen is for domain3.com/subpage to redirect to domain2.com/subpage, however the original redirect of the vanity URL is overriding any attempts we make.
Is this kind of redirect possible?
Here is the original redirect in domain1.com's htaccess file:
RewriteCond %{HTTP:Host} ^www\.domain3\.com$
RewriteRule (.*) http\://www\.domain2\.com/spanish-version [I,R]
These are the attempts at making the needed redirect happen (also in domain1.com's htaccess file):
RewriteCond %{HTTP:Host} ^www\.domain3\.com/subpage$
RewriteRule (.*) http\://www\.domain2\.com/spanish-version/subpage [I,R]
RewriteRule ^domain3\.com/subpage?$ /spanish-version/subpage [NC,R=302,U]
Rules for your domain3 should look like this :
RewriteCond %{HTTP:HOST} ^(www\.)?domain3\.com$ [NC]
RewriteRule ^/?(subpage_name)/?$ http://www.domain2.com/$1 [NC,R,L]
This will redirect
www.domain3.com/subpage
to
www.domain2.com/subpage
(www.)? in HTTP:HOST variable is to make the "www" part optional in url, so in this case
urls with or without "www" would also work.

htaccess 301 redirecting of subdomain - home page issues

I needed to 301 redirect my subdomain URL to the Directory structure URL.
So blogs.mydomain.com should be redirected to www.mydomain.com/blog/ and below is the .htaccess that is changed.
RewriteCond %{HTTP_HOST} ^blogs.sampledomain.com
RewriteRule ^(.*)$ http://www.sampledomain.com/blog/$1 [L,NC,QSA,R=301]
It works fine and the blogs part is taken care. But, when I try to go to www.sampledomain.com it takes me to www.sampledomain.com/blog.
With this I am not able to land onto the homepage at all.

301 redirect addon domain improperly

I have a website with url http://abc.com/myfolder/, now i add a addon domain "xyz.com" in cpanel and point it to myfolder. The addon domain is working successfully. xyz.com is showing what http://abc.com/myfolder/ showing. However http://abc.com/myfolder/ is already indexed in google, thus i want to do a 301 redirect from http://abc.com/myfolder/ to xyz.com. I searched online and did something like below.
RewriteEngine On
RewriteBase /myfolder/
RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L]
but the redirect failed. showing "The page isn't redirecting properly". What can i do
you have first to check that the host is abc.com before applying the rule, otherwise, you end up applying the rule for both abc.com and xyz.com which result an infinite redirection loop.
RewriteEngine On
RewriteCond %{HTTP_HOST} abc.com$
RewriteRule ^myfolder/?(.*)$ http://www.xyz.com/$1 [R=301,L,NC]