301 Redirect WITHOUT subdirectories/query string - apache

I've been searching for this for hours now. Everything I find does the exact opposite.
I want to 301 redirect ALL traffic from an old domain to a new one. I DON'T want anything to pass across to the new domain, just redirect to the domain itself and nothing else.
I would prefer to do it in a vhost, but htaccess is fine.

In your old domain vhost config (or .htaccess):
RewriteRule .* http://newdomain.com/? [R=301,L]

Related

.htaccess 301 redirect page specific + wildcard the rest

The site I'm working has moved to a new domain, with a completely different site structure and file naming.
I've set up a .htaccess file to re-direct important pages to the equivalent pages on the new domain:
RewriteEngine On
Redirect 301 /oldpage1/ http://www.newdomain.org/newpage1
Redirect 301 /folder/oldpage2/ http://www.newdomain.org/newpage2
Redirect 301 /oldpage3/ http://www.newdomain.org/folder/another-newpage
...
...and so on.
Now, I want to catch all other URLs under the old domain and direct them to the homepage of the new site. So something like:
Redirect 301 /*/ http://www.newdomain.org
But how is this really done?
Thank you for any help!
Upfront, RewriteEngine On is not necessary with Redirect directives, because RewriteEngine is part of mod_rewrite, and Redirect belongs to mod_alias. These are two different ways of achieving a similar goal.
Now, just to answer the question, you may use RedirectMatch for this
RedirectMatch / http://www.newdomain.org
This will redirect any path from the old domain to the home page of the new domain.
Please note, that the Redirect directive uses the "old" URL as a prefix
Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL.
This means
Redirect /oldpage1/ http://www.newdomain.org/newpage1
will redirect all URLs, that start with /oldpage1/, not just oldpage1 alone.
And finally, never test with 301!

Redirect with .htaccess to exact URL provided

So I want to redirect from old sites url to new one. Lets say example.com/en/some/stuff/foo/bar needs to be redirected to example.com/some/stuff.
Here is what I have at he moment:
Redirect 301 /en/some/stuff/foo/bar/ /some/stuff/
The problem is that I end up being redirected here example.com/some/stuff/foo/bar, but I need as I defined inside .htaccess example.com/some/stuff.
How to redirect properly to exact URL I have provided without anything extra.
You can use this redirect rule with regex in your site root .htaccess:
RewriteEngine On
RewriteRule ^en/(some/stuff)/.+ /$1 [L,NC,R=301]
Make sure to test it in a new browser to avoid old cache.

Redirect help from old domain to new domain, using cname www, but use htaccess to exclude specific directories?

We moved our website from our server, domainname.com to another server (a SaaS). We pointed the www via CNAME record in WHM (in order to preserve the MX and other services on the "old" server)
ALL www.domain.com traffic is now sent to the new SaaS. Works great.
For non-www links, we are using:
RewriteCond %{HTTP_HOST} !^(.*)\.domainname\.com$ [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]
and that works great too.
WE ALSO own domain-name.com, and that also lives on the "old" server.
domain-name.com is a misspelling of our company name, and we want all traffic from www and non-www.domain-name to 301 to domainname.com
That is easy too! In the domain-name .htaccess:
RewriteRule .* http://www.domainname.com/ [R=301,L]
Now the fun (and where I could use some help) --
We have many existing links, such as:
www.domainname.com/images/foldername1/image_300x300.png
www.domainname.com/images/foldername2/image_300x300.png
www.domainname.com/html_pages/page1.html
www.domainname.com/html_pages/page2.html
etc... And I'd really like to preserve these without getting sent to the new SaaS and thereby 404ing.
OR -- as an option, the entire contents of www.domainname.com has been cloned to www.domain-name.com -- so we could 301
http://www.domainname.com/images/foldername1/image_300x300.png to
http://www.domain-name.com/images/foldername1/image_300x300.png
and that would be perfect too... Actually, that would be preferred.
I have tried a dozen suggestions from other doing global redirects... but because the primary www.domainname.com is getting its redirect from CNAME, and we MUST trap for non-www in domainname.com's htaccess, HOW can we constrain specific directories (www or not) to 301 to a new server AND also force www.domain-name.com (and non-www) to 301 to www.domainname.com (unless the path is
/images/
/html_pages/
/secret_hiding_place/
Any ideas?
Also have to be careful for 301 loops.
Thanks for any clues or ideas.
THANKS!!!
J

301 re-direct OLD home-page to specfic page, all else to NEW homepage

I'm moving my site to a new domain where the content from the HOMEPAGE on the OLD domain now lives on a specific page on the NEW domain. My question is- how do i re-direct the OLD homepage to this specific page on the new domain, and then send every other request from the old domain to the homepage of the NEW domain. I know thats kind of confusing- here's an example. Working with apache so will most likely do this in the htaccess file of the old domain.
I need
old.com -> new.com/specific-page
everything else -> new.com
The easiest way to do this is by using mod_rewrite on the old domain. Put the following directives in a .htaccess file in the www-root.
RewriteEngine on
RewriteRule ^$ http://new.com/specific-page [R,L]
RewriteRule ^ http://new.com [R,L]
The first rule will only match when the url-path is empty (that is, if you request http://old.com/). Any url that is not matched by the first rule will be matched by the second rule and redirected that way.
When both rules work as expected, change the R flag to R=301 (so that it says [R=301,L]). This makes the redirect permanent.

Redirect from one domain to another, without the user realizing it

I have a bunch of domains on on of my servers. I'd like to be able to redirect some domains to a different domain without the user knowing, so not a 301 redirect.
An example, redirect domain.com to masterdomain.com/sites/domain.com. So when visiting domain.com, the user would be displayed with the data on masterdomain.com/sites/domain.com.
Also masterdomain.com and domain.com are on the same server.
How could I do this using Apache? mod_rewritem mod_alias?
If both host names use the same document root, you can do this:
RewriteCond %{HTTP_HOST} =example.com
RewriteRule !^sites/example\.com(/|$) sites/example.com%{REQUEST_URI} [L]
This rule will prepend /sites/example.com if the requested URI path does not already starts with that.
GoDaddy calls this a domain Alais.
Here is a link where it is explained
http://webwizardworks.com/web-design/domain-alias.html