htaccess domain redirect to newdomain - php

I have the domain www.oldsite.com and i set a redirect to forward to www.newsite.com/new
but when i google search old site all of its sub links go to www.newsite.com/new/sublink
How do i edit the htaccess file so that the sub links never pass though
RewriteCond %{HTTP_HOST} ^oldsite\.com*$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com*$
RewriteRule ^/?$ "http\:\/\/www\.newsite\.com\/new" [R=301,L]
In short all links involved in oldsite.com should redirect to newsite.com/new
I read the below but it didnt seem to help to much.
htaccess: domain hosted on subdirectory

The below .htaccess should be place on the root folder of the old domain only:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new
No URLs from the old site will be passed down to the new site, they will all be sent to /new.
NOTE: make sure you do not have any additional .htaccess files in other folders of the old domain as those will set null the previous rules.
If you want to send only the main domain to the new one without any URLs within:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^/?$ http://www.newsite.com/new [R=301,L]
A different way would be to handle all the URLs on the new site, which would be like the below .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new%{REQUEST_URI} [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new/someurl
If you do not wish the new to show up simple remove /new from the rule above.

Related

Redirect everything (pages and subdomains) to new domain page

I want to redirect all pages (including subdomains) of an old domain to a single page on the new domain. All pages will be redirect to the same page on the new domain.
I have countless subdomains on the domain I want to redirect. For this reason I need a dynamic code that redirects all pages, because there is no way for me to find all subdomains.
I have pages like this:
old.com
old.com/page1
old.com/page2
sub.old.com
sub2.old.com
sub2.old.com/page
I tried all variations of this code but the subdomains won't redirect:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^old\.com$ [NC]
RewriteRule ^(.*)$ https://new.com/we-moved/ [R=301,L]
If you are using cPanel, Directly use the Redirect Option. IF you want to edit .htaccess file, Checkout my Code:
RewriteCond %{HTTP_HOST} ^clsh\.ga$ [OR]
RewriteCond %{HTTP_HOST} ^www\.clsh\.ga$
RewriteRule ^/?$ "https\:\/\/url\.cloudmate\.in\/" [R=301,L]
This htaccess redirects https://clsh.ga to new Domain https://url.cloudmate.in .
If your htaccess does not redirect then also, try enabling mod_rewrite.c
This should work for you:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} (?:^|\.)old\.com$ [NC]
RewriteRule ^ https://new.com/we-moved/? [R=301,L]
(?:^|\.)old\.com$ will match root domain or any subdomain.
? will discard any query string in redirect.

htaccess forward to subfolder but hide subfolder name

I have an issue writing some regex to go inside my htaccess file.
Basically, my site has been setup so that index.php and all other site files are not in the root (public_html) directory but instead are in http://fitnessquiz.co.uk/fitnessquiz.co.uk/
Initially I tried the following in my public_html folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^fitnessquiz.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.fitnessquiz.co.uk$
RewriteCond %{REQUEST_URI} !fitnessquiz.co.uk/
RewriteRule (.*) /fitnessquiz.co.uk/$1 [L]
which correctly navigates to my homepage and displays the url correctly but then when I click any link I get a "no input file specified" message. So then I tried replacing with:
RewriteCond %{REQUEST_URI} !^/fitnessquiz.co.uk/
RewriteRule ^(.*)$ /fitnessquiz.co.uk/$1 [L,R=301]
After which the site works but every url looks like this:
http://fitnessquiz.co.uk/fitnessquiz.co.uk/someotherfolder/etc.php
I've tried various htaccess regex solutions listed elsewhere on here but none seem to work, how do I accomplish both of these things i.e. redirect to /fitnessquiz.co.uk for every url but hide the duplicate url name/folder. Im on a shared server so don't have permissions to change any server/apache settings directly.
According to this answer by nuked on a previous post you could try:
RewriteCond %{THE_REQUEST} ^GET\ /fitnessquiz.co.uk/
RewriteCond %{HTTP_HOST} ^(www\.)?fitnessquiz.co.uk$
RewriteRule ^fitnessquiz.co.uk/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?fitnessquiz.co.uk$
RewriteRule !^fitnessquiz.co.uk/ fitnessquiz.co.uk%{REQUEST_URI} [L]
This set of rules worked for me on a very similar situation. I had employed the same cure, (re-direct if calling the folder and hide after re-writing it) but I never got the order right on my own. Thus I kept seeing the page not found errors too. Below is my attempt to explain the actions, for my own learning, hopefully others too.
RewriteCond %{THE_REQUEST} ^GET\ /fitnessquiz.co.uk/
Is asking the question, does THE_REQUEST contain the subfolder you need to hide?
RewriteCond %{HTTP_HOST} ^(www\.)?fitnessquiz.co.uk$
Checks if the request is for the correct host.
RewriteRule ^fitnessquiz.co.uk/(.*) /$1 [L,R=301]
Rewrite the URL as one without the subfolder and call the new link in the redirected browser. Note:
L : Last step. Stop processing other rules
R=301 : After re-writing, redirect the browser to the new URL.
When the page is redirected it has no subfolder so the first RewriteRule is skipped. And then
RewriteCond %{HTTP_HOST} ^(www\.)?fitnessquiz.co.uk$
checks if calling the right host. And then
RewriteRule !^fitnessquiz.co.uk/ fitnessquiz.co.uk%{REQUEST_URI} [L]
rewrites the url that has not the subfolder to use the correct subfolder without redirecting the page, and while hiding actual subfolder from the browser. Again note:
L : Last step. Stop processing other rules

Rewrite a secondary domain to a subfolder

I bought two domains:
www.juridischehulponline.nl
www.onlinejuridischehulp.nl
And I'd like them to link to the subfolder of my hosting: www.zuidveste.eu/juridisch and the new domain has to be displayed as the new domain. So if I surf to www.juridischehulponline.nl I'd like to see: www.juridischehulponline.nl and not www.zuidveste.eu/juridisch.
However, if I rewrite and redirect the subfolder to the new domain, I get a: "too many redirects" error. Since it'll go to www.juridischehulponline.nl where an .htaccess is found which will redirect to www.juridsichehulponline.nl
and if I proxy the domain, my new domain keeps being displayed, however simple blogging systems, such as cutenews, won't work, because they see the absolute path as www.zuidveste.eu/juridisch. But due to the .htaccess, that part will be rewritten and the path of www.juridischehulponline.nl/index.php is given; which doesn't exist.
I've deleted the .htaccess in the /juridisch folder, but I don't know how this can be solved.
Can anyone help me?
Regards,
I wouldn't use proxy, but improve the .htaccess-structure: place only a .htaccess in your zuidveste.eu root:
Options -Indexes
RewriteEngine ON
Options +FollowSymLinks
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^juridischehulponline.nl [NC]
RewriteRule ^(.*)$ http://www.juridischehulponline.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^onlinejuridischehulp.nl [NC]
RewriteRule ^(.*)$ http://www.onlinejuridischehulp.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^zuidveste.eu [NC]
RewriteRule ^(.*)$ http://www.zuidveste.eu/$1 [R=301,L]
#rewrite other domains to the subfolder, keeping the attributes
RewriteCond %{HTTP_HOST} ^www.juridischehulponline.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.onlinejuridischehulp.nl [NC]
RewriteCond %{REQUEST_URI} !^/juridisch/
RewriteRule ^(.*)$ /juridisch/$1 [QSA,L]
This code redirects the 3 non-www domains to their www-alternative, so the visitors will see that they are redirected. On the other hand, if they visit the 2 .nl-domains, the urls will be rewritten and the users will not see this change in their address-bar.
Nevertheless, take care for duplicate content in search engines. I recommend using a canonical-meta-tag, as explained here: http://moz.com/learn/seo/duplicate-content

Redirect all non-www to www except one subdirectory using htaccess.

If want to redirect all non-www requests to my site to the www version. All I need to do is add the following code to my .htaccess file.
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule .* http://www.mydomain.com%{REQUEST_URI} [R=301,L]
The problem is that when I write for example mydomain.com/products-1 (hidden URL for mydomain.com/products?category=1), all parameters become visible, even though they are specified on the .htaccess file, and I get an output url (after the redirect) of www.mydomain.com/products-1?category=1
How can I fix this? Is there any kind of problems with the .htaccess code above?
Try Changing your RewriteRule:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I prefer this because it will catch all *.domain.com. If that is not what you want, then use your original HTTP_HOST rule.
If my logic is working this morning, this rule should rewrite any requests that do not match:
www.example.com
and do not contain
/subfolder
to
www.domain.com/URI

htaccess redirect website

I'm trying to redirect all my visitors from the old domain that I use to the new one.
Here is the content of the .htaccess file that I use
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !foobar.com$ [NC]
RewriteRule ^(.*)$ http://foobar.com/$1 [L,R=301]
where http://foobar.com is the new domain.
The code above works but only if the visitor type http://olddomain.com.
What I mean is when the visitor types
http://olddomain.com/terms.php he should be redirected to http://foobar.com/terms.php
I want that whatever the visitor types after the old domain name (like http://olddomain.com/privacy.php, http://olddomain.com/users.php, etc) they go to
http://foobar.com/ not to http://foobar.com/privacy.php etc.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^foobar\.com$ [NC]
RewriteRule .* http://foobar.com%{REQUEST_URI} [L,R=301]

Categories