.htaccess Redirect all pages to one page - .htaccess

htaccess snippets to redirect all pages to one page but none of them are working for me.
I need olddomain.com , olddomain.com/pricing , olddomain.com/about , etc all to point to newdomain.com.
So olddomain.com/pricing shout not go to new domain.com/pricing.
It should just go to newdomain.com.
How can I do this?

Nothing simpler then that.
If it are different webservers, you can write this on the old ones:
RewriteEngine On
RewriteRule ^(.*)$ http://www.newdomain.com [R=301,L]
^(.*)$ means everything
http://www.newdomain.com is the target
If it is still the same webserver
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.*)newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com [L,R=301]
It is pretty the same, but you have the condition, that the host is not newdomain.com.

RedirectMatch 301 (?i)/* http://www.yourdomain.com/WHATEVER
or
RedirectMatch 301 (?i)/OLD/* http://www.yourdomain.com/WHATEVER

This will go in the htaccess in your old domain root. If they are not on the same server you don't need the RewriteCond line.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain.com$ [NC]
RewriteRule ^(.*) http://newdomain.com/ [R=301,L]
Try this and let me know how it works for you.

Related

301 redirect to new domain with same url structure

I have a Magento website that is moving to a new domain. Im looking to 301 redirect all pages from the old domain to the new domain keeping same url structure.
I've updated the .htaccess file on my old domain with:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^new-domain.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]
The issue: The above seems to redirect every instance of: old-domain.com/subdir/whatever only just to the main domain: new-domain.com.
I'd be looking to redirect old-domain.com/subdir/whatever to: new-domain.com/subdir/whatever.
Any idea on what could be wrong?
Adjust your rule to use REQUEST_URI variable which is not dependent on the directory of .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewriteRule ^ http://new-domain.com%{REQUEST_URI} [R=301,L,NE]
Better to clear your browser cache before testing this rule.
PS: You need to match hostname condition to old-host not the new-host.
This should redirect and retain the path after the main domain.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]

Htaccess Redirect

I am sure this is pretty simple, but i just cant find the right code for it.
I need to redirect everything, old domain, with and without www all sub pages.any random link that may be out there to www.newdomain.com
Here is mine at the moment, and it redirects well, exceprt for one thing
www.old-doamin.com/old-page - redirects to www.newdomain.com/old-page
When it should be going to the home page of the new page.
thank you for the help.
RewriteCond %{HTTP_HOST} ^old-domain.com/$
RewriteRule (.*) http://www.old-domain.com/$1 [R=301,L]
RedirectMatch 301 ^/(.*)http://www.newdomain.com/$1
Why dont you do it through DNS? CNAME redirect would probably be best so the old-domain.com traffic is redirected?
If you want to go with htaccess, this should do the trick:
RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/ [L,R=301]
Make www optional, this should work for you:
RewriteCond %{HTTP_HOST} old-domain\.com$ [NC]
RewriteRule ^ http://www.newdomain.com/ [R=301,L]
Don't forget to take out both of your existing rules.

Why are is my homepage not redirecting?

Read a ton on creating the proper redirects, but still having an issue.
Moving a site from one domain unto another. The directory structure has changed as well. The subpages are working great, but the home page isn't. Here the code that I'm using:
RewriteEngine on
//301 Redirect Old File
RewriteRule oldsite.net newsite.com [R=301,L]
RewriteRule ^p_gallery.* http://www.newsite.com/gallery [R=301,L]
RewriteRule ^p_purchase.* http://www.shop.newsite.com [R=301,L]
Thanks!
Make sure you have enabled mod_rewrite.
Because your first rule is wrong:
RewriteRule oldsite.net newsite.com [R=301,L]
You can only match REQUEST_URI in the RewriteRule.
It should be like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.net$ [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [R=301,L]

.htaccess redirect to subfolder, not working perfectly

I have written a simple redirect condition as:
RewriteCond %{HTTP_HOST} !^my-domain\.com$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]
It redirects correctly from www.mysite.com to mysite.com/hu/
But it does not redirect mysite.com to mysite.com/hu/
Please help
You've cleary copied this code without understanding it. This is a typical htaccess to remove the www. part of a domain.
To redirect your homepage to a subfolder, use this code instead :
RewriteCond %{HTTP_HOST} ^(www\.)?my-domain\.com$
RewriteCond %{REQUEST_URI} !^hu/$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]

Problem 301 redirect not allowing login in the backend

I am finding some problems in the htaccess of CMS with a 301 redirect.
When trying to solve canonical urls (redirecting site to www.site) I got the problem that I cannot log in in the back end (www.site/admin).
The htaccess condition is:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.site\.co.uk$
RewriteRule (.*) http://www.site.co.uk$1 [R=301,L]
I guess I need to include a expression that allows the URI /admin not to be redirected, but how?
Like this, for example:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.co.uk
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [R=301,L]

Resources