I'm having some trouble setting up a htaccess file. Currently I have 15 domains serving their own website. Now moving this to a single website and domain, I want to serve a htaccess with 301 rules for the old urls. The destination url depends on the domainname of the old url..
E.g.
http://www.previouswebsiteinspanish.com/contacto should be permanently rewritten to http://www.newcentralwebsite.eu/es/contact
I understand that I have to use the RewriteCond but I'm not familiar enough with it to get it working.
RewriteCond %{HTTP_REFERER} !^http://(www\.)?previouswebsiteinspanish/.*$ [NC]
RewriteRule ^([^/.]+)/contacto$ /$1/contact [R=301,L]
Thanks in advance!
You current condition is that the rule will be executed under the condition that the referring page is not on the old domain. That's most likely not what you want to do. :)
You want to check the %{HTTP_HOST} parameter, which contains only the hostname part of the currently requested URL.
Assuming you want to redirect everything on the old domain to the es subfolder, this rule will do it.
RewriteCond %{HTTP_HOST} ^(www\.)?previouswebsiteinspanish.com$ [NC]
RewriteRule ^(.*)$ http://www.newcentralwebsite.eu/es/$1 [R=301,L]
Then you'll have to add similar rules for each old domain.
RewriteCond %{HTTP_HOST} ^(www\.)?previouswebsiteinspanish\.com$ [NC]
RewriteRule ^contacto$ http://www.newcentralwebsite.eu/es/contact [R=301,L]
You need to check HTTP_HOST which is the hostname of the requested site.
From your example the rule I wrote is
RewriteCond %{HTTP_HOST} ^(www\.)?previouswebsiteinspanish\.com$ [NC]
RewriteRule ^contacto$ http://www.newcentralwebsite.eu/es/contact [R=301,L]
Add such rules to your .htaccess.
You have to write such rules for each domain.
In above case you have change in url too, so you may have to handle such special cases too.
Related
I'm trying to redirect a url but I can't seem to make it work for some reason. I'm trying to redirect my.domain.com/rss/abc/ to my.domain.com/rss/abc/?type=555
I've put this in my .htaccess
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/rss/abc/?$ /rss/abc/?type=555 [R=301,L]
Any pointers ? This is on a old TYPO3 site. Anyway it could hijack the request before doing the redirect ?
I can only recommend to use some kind of online htaccess rewrite rule checker, for example https://htaccess.madewithlove.com/ (not the only one, and no real preferance or recommendation about others).
Your rewrite rule is wrong, it should be:
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^rss/abc/?$ /rss/abc/?type=555 [R=301,L]
I have a website www.mainwebsite.com with a page located at www.mainpage.com/pagename
I need to redirect a new domian name to this page. so www.newdomainname.com should redirect to www.mainpage.com/pagename
How can I do this with the htaccess?
My site is using Perch Runway too not sure if this will change anything?
Thanks
You can achieve that by using the following rules in your .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomainname\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.newdomainname\.com [NC]
RewriteRule ^(.*)$ http://www.mainpage.com/pagename/$1 [L,R=301,NC]
So if either of newdomainname.com or www.newdomainname.com it will then using a 301 redirect take you to www.mainpage.com/pagename.
Make sure you clear your cache before you test this.
I have two domains, one old and one new. The structure on both of the sites is identical so what I need is to transfer anything after the domain to the new page
http://testurl.com/absolutely/anything/here
to
http://testurl2.com/absolutely/anything/here
ive tried:
RewriteRule ^(.*) http://testurl2.com/$1
but nothing is working :/
what every comes after the main url needs to be sent to the new domain.
Try this .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^testurl.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.testurl.com$
RewriteRule (.*)$ http://testurl2.com/$1 [R=301,L]
[R=301] flag is used to redirect URL by status 301
[L] flag is used to break rule matching for further rules if it matched given rule.
I have multiple domains on my server. I want to redirect all of them to one (example.net).
My .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]
I’m redirecting all URLs on my server to one main domain, but that domain is also redirecting to itself. So www.example.net returns 301 Moved Permanently and redirects back to itself. I’m told that this isn’t good for SEO. How could I fix this?
You need to add a Rewritecond to prevent it from redirecting when you’re already on the domain that you want. There are loads of examples online if you google it, or see the RewriteCond section of Apache’s mod_rewrite documentation.
What you’re looking for is something like:
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.example\.net
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]
Just small note:
Thanks goes to TRiG, but I had to remove one slash to make it work correctly (coz it added two slashes after domain name). This works for me:
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.example\.net
RewriteRule ^(.*)$ http://www.example.net$1 [R=301,L]
I have checked previous questions, I believe this is quite simple but I can't seem to work it out.
In my .htaccess file I currently have
RewriteCond %{HTTP_HOST} !^www\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]
However this is causing a problem as it also redirecting any sub-domains (specifically au.bodycleansediet.com and ca.bodycleansediet.com) to www.bodycleansediet.com
I want them NOT be to be redirected so they can be viewed on their sub-domains.
I know I need to add an exception/re-write rule but I am not sure how to construct it.
Any advice on how to construct this?
Should not something along the following lines work
RewriteCond %{HTTP_HOST} !^(www|ca|au)\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]
Since you are basically checking if not (www OR ca OR au) then do your redirect.