Updating href in url redirect htaccess - wordpress

I am trying to show the content of one domain with the url of another. So for example if I go to example1.com I would like to show the content of example2.com without changing the url name.
What I have right now is the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1.com
RewriteRule ^(.*) example2.com/$1 [P]
This works great, but the next step to this that I would like is for internal hrefs of example2.com to remain as example1.com in the url.
So if on the copied page there would be a link to example2.com/about I would like for it to become example1.com/about instead.
Is this possible with htaccess? if not what would be the best way to approach this.
P.S. This is a WordPress site - so if anyone has a good WP specific way of achieving the above that would be fine too.
Thanks in advance!

Related

Wordpress Home page URL changing to /?i=1 - issue

When I try to access my Wordpress website directly or from google, the Home page URL automatically adding /?i=1 and sometimes /?i=2 to the URL in the address bar.
I think it's a very simple to solve it, but I tried many things and didn't work.
So I wonder how can I solve this to be only the URL without /?i=1 or /?i=2 ?
/?i=1 or /?i=2 protects your website from bots and is mostly applied by free hosting services and if you use any .htaccess code to remove it than all ? parameters will removed and redirect you to homepage
Try resetting your wordpress permalink from admin end. If you don't know how to do that check this video. As this is not normal behavior of wordpress you can also check your .htaccess file.
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
Add this in htaccess

301 Redirect server IP to domain while keeping query string

I've searched around but no one has the exact issue as me, I can't figure out how to do this without messing up the site.
-My website is WordPress.
-Vultr VPS with Server Pilot
-Currently the site is behind cloudflare and this all works.
Issue: I have an entire version of the website still browsable using the server IP and I can't figure out how to 301 redirect it.
Example if you happen to go to my website xxx.x.xx.xx then you can browse the entire website without ever being redirected, the query strings and everything shows in the address bar example:
http://xxx.x.xx.xx/category/page/?utm_source=aa&utm_medium=bb&utm_campaign=cc
Someone could browse the entire site like this, I do not want this I want to redirect it to my domain. In WordPress general settings I do have the Site URL and WordPress URL set to my domain name but I don't know why this is happening.
I can't give examples of what I've tried because they all failed and I had to delete them from my .htaccess file, basically, I want to 301 redirect any request coming to the IP and send them to the domain of the site carrying over their query string and everything, help is really appreciated.
Did you try this in your .htaccess file?
RewriteEngine On
RewriteBase /
Redirect 301 /old_page1/ http://example.com/new_page1
Redirect 301 /old_page2/ http://example.com/new_page2
Fixed it by using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx
RewriteRule (.*) https://example.com/$1 [R=301,L]
</IfModule>
Dot's must be escaped and the query strings get carried along just fine, be sure to leave the trailing slash as it's displayed above or else your page might appear like this: https://example.compage/subpage
Leaving the trailing slash in the rewrite rule will prevent that so it would be: https://example.com/page/subpage

301 redirect url with all url's that start with main url - Wordpress

We want to make a 301 redirect in the htacces in our wordpress installation for the following situation. This morning in our webmaster tools we see 8000 new 404 pages not found. In the image below we have made a printscreen. We do not know were these url's come from because we do not use this url structure. As you can see in the printscreen everything starts with:
order/order.html?AddID for example: order/order.html?AddID=1014&Rand=920505296661072670
It looks like the old owner of the url has something to do with this. Now we want to redirect everything that starts with order/order.html?AddID to the homepage. At this moment we see 8000 not found with exactly the same url and only a different AddID.
Is this possible and if so does someone has the best way to redirect these url's?
You should just tell Google not to take into account these url parameters. In Webmaster tools, go to Exploration -> URL Parameters and declare that AddID and Rand do not change the page rendering.
Insert this code just below RewriteBase line in your WP .htaccess:
RewriteCond %{QUERY_STRING} ^AddID=.+ [NC]
RewriteRule ^order/order\.html$ / [L,R=301,NC]

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

What is the canonical url of my website with www or without?

For my site: http://www.indiacustomercare.com which one is the canonical url with www or without www?
I've not changed any settings.
I remember that I changed this to www. in one for my previous drupal-6 website but I've forgotten it now(I did not change .htaccess).
So if I access my site as http://indiacustomercare.com then all pages seem to be without www ( except for those in the footer which are hardcoded with www...)
Similarly for when I access my site as http://www.indiacustomercare.com all web pages seem to have www prefix.
So what is my site's default www or without www?
Yes, in Drupal .htaccess there are pre-defined settings for this. Go to line 90-97, choose which domain you want to use (with or without www), uncomment the appropriate lines and add there your domain.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
This one redirects from example.com to www.example.com.
There is also the opposite direction below.
You choose, but it's considered best practice to go with either one or the other, and not leave both available. If you set up a 301 Redirect, it is nicer for search engines.

Resources