Redirect all posts on wordpress - redirect

I moved my site to a new host but by accident permalink was changed. First i had a /%postname%.html and after moving to new host it got changed to /%postname%/ .
I fixed the permalink and is working fine except when Google crawls my website google search results return 404 error pages.
I tried every redirect plugin and nothing is working. I want to redirect every post that is http://www.website.com/sample-post/ to http://www.website.com/sample-post.html
I can not add every single post because there are around 100k posts.
Any ideas?
thanks

Firstly you are attempting to treat the symptom, not the problem. This will cause more issues for you in the future.
However, the best way to do what you want is to use rewrite rules in apache's .htaccess file.
Something like this should work. Modify as desired.
# add .html file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ /$1.html [L]

Related

How can i redirect a not working url or removing the indexing of the url from google search console

How can i remove the indexing of the url from google search, I have this url, and we need to remove it because it does not work well.
This is the url - https://www.avon.com.gt/cam-home?curnav=Cuidado%20Personal
When im trying to redirect this url it is saying invalid url(because the link has one space between Cuidado and Personal). If you can help with how can i redirect this url from apache web server configuration, will help me a lot.
I think the meta tag in this case not is the solution because the meta tag would have to be put in the home. If I do this google no indexing anymore the home.
Maybe Google search console but i think it will do only temporary.
Thanks you so much for your help.
You can request from google that they remove one or more web pages from the search console. Your web page is https://www.avon.com.gt/cam-home, you do not include query parameters appended on to the end of the URL.
Find the page in Google Search Console click Google Index > Remove URLs.
In can then take google several days to action your request.
You do not seem that experienced so if you want to re-direct to another webpage while you are waiting for google to action your request just add some javascript to the page something like this...
<script>
window.location.href = 'http://www.youtube.com';
</script>
If you are feeling more adventurous you can have apache re-write the url on the fly to direct people to your new page, something like this...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^avon.com [NC]
RewriteCond %{REQUEST_URI} cam-home [NC]
RewriteRule ^(.*)/+$ /new-page

Redirect 301 after domain change

I had to do a domain change on a website so I moved from www.mydomain.it to www.mydomain.eu. At the moment I don't have full control on the .it domain so when it was the time to make the domain change I asked the hosting provider to make a 301 redirect of the .it to the .eu so as a result, I got all the pages of the .it website redirected to my .eu's homepage (no 404 errors) because the previous website used queries as pages' URLs.
This is a link example of the previous website:
http://www.mydomain.it/index.php?page=lkr_pg_chisiamo
So what I started getting after the redirect was:
https://www.mydomain.eu/index.php?page=lkr_pg_chisiamo
which gave me back the homepage content as a result and not a 404 error.
The old website had at least 10k links like that one so each of them started having the behavior of the link above, I got the homepage content for all links. In the beginning, I thought it was a good thing for me because I wasn't getting 404 errors but then I started digging around on the web and I found out to not be a good practice because all links might be recognized as soft 404 errors.
Obviously before I made the domain change I had created all the 301 redirects of the most important pages of the website like this:
RewriteCond %{QUERY_STRING} ^page=lkr_pg_chisiamo$
RewriteRule ^(.*)$ https://www.mydomain.eu/chi-siamo/? [R=301,L]
RewriteCond %{QUERY_STRING} ^page=lkr_pg_contattaci&form_key=25-8124355$
RewriteRule ^(.*)$ https://www.mydomain.eu/contatti/? [R=301,L]
And so on..
Obviously, I didn't do that for all the 10k pages, but just the most important, so the other links are still pointing to the homepage content.
After I did this, I told Google I had changed the domain through the Google Search Console.
After a few weeks, I started seeing some results on Google but after one month I'm not still happy with them, I think I lost rank on Google. I know it could take a while more to do everything and that I should probably lose 3% of my "domain juice" after a domain change but what I was wondering if I have done everything in the right way in order to not lose rank.
My concern now is about all the links that I wasn't able to redirect and that has been redirected automatically and started getting the homepage content. Should I be worried about them?
How should I manage them?
Should I redirect them to another page which is not the homepage?
If yes, is there a way to redirect all those links (just those) even though I have all the other redirects in my .htaccess file?
Was there a better way to redirect all the 10k links of that type? How would I be able to do that?
You asked this 6 months ago, but i hope i can help you.
Add this to your .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.it$ [NC]
RewriteRule ^(.*)$ http://mydomain.eu [R=301,L]
This should redirect all links to your new domain.
About Google Search Console, take a look here: https://support.google.com/webmasters/answer/93633?hl=en
About changing domain, look at: https://support.google.com/webmasters/answer/6033049?hl=en
Hope this helps!
Brhaka

How to stop Facebook crawler from following 301 redirect in .htaccess?

I am in the final stage of updating a website and changed many url's for SEO purposes. Now I want to keep the social scores for most pages, most importantly the Facebook likes and comments. It has been confirmed that this is possible. See the following link for reference: How can I move a URL via 301 redirect and retain the page's Facebook likes and Open Graph information?
og:url on newurl.html page should be oldurl.html -> done
keep valid page with old og tags named oldurl.html -> done
redirect from oldurl.html to newurl.html -> done
exempt the Facebook crawler from this redirect -> I don't know how
I can't find an answer on how to this and there have been other people asking the same question with no answer. Only got purple links left on this subject and do not know what to do or search anymore.
How do does one stop a crawler from following a redirect?
Edit. I know now that this won't work this way but it is the best I can do. One of the conditions being don't be Facebook and then all the rules bundled together for that condition without having to repeat the condition for every rule:
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^old-url1\.html$ http://domain.com/new-folder/new-url1.html? [N,R=301]
RewriteRule ^old-url2\.html$ http://domain.com/new-folder/new-url2.html? [N,R=301]
RewriteRule ^old-url3\.html$ http://domain.com/new-folder/new-url3.html? [L,R=301]
Edit2. I'll have to go with the repeat for every rule. Many url's changed name. Something more elegant might be possible but that is way beyond my ability. Does it have a significant influence on page load time if the code below is repeated 60 times with different url's?
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule ^old-url1\.html$ http://domain.com/new-folder/new-url1.html? [L,R=301]

301 Redirect URL with Trailing Slash to "Sub directory" with same name

The company I work for recently took over a site that is built in WordPress, apparently Google has indexed several pages with a trailing / that coupled with the fact that the previous company programmer made the site require some information from the URL.
So, Google has indexed domain.com/featured-something/something/ and I need to redirect these pages to domain.com/featured-something/something/?something=something&somethingelse=something else
I tried this code for a redirect, but only works without the trailing slash:
RewriteRule ^featured-something/something?$ http://domain.com/featured-something/something/?start=0&pt=&bed=&bat=&subdiv=Aqua&sub=&pr=&display=quick [R=301,L]
I had added some code before all of the rules to redirect to a non slashed version first, then these, but that created an infinite redirect loop.
Can someone please help me out?
Thanks
Karl
p.s. The GET string is unique to each different URL, unfortunately, so will have to create rules for each url.
Well, I never gave up the search, even after I posted here.. Looks a little inelegant, but I found a way to make it work (thanks in part to another Stack Overflow question/answer) Before each and every RewriteRule I had to add a RewriteCond to not rewrite the URL W/ the query string
RewriteCond %{QUERY_STRING} !([^&]+&)*start=0(&.*)?$
I also changed the ? in the Rule to a /
No more infinite loop and redirects all of Google's indexed pages properly.

htaccess rewrite one file type with get variables

i think header is confusing, here is the situation.
i host some video files and want to use on my website. but only on my website. if you realized facebook did this. but we dont have servers like them -nginx i guess-.
finally i want to redirect all requests to a certain page. like that
if someone request that
http://www.blabla.com/videos/1.mpg?hash=12345&expire=1234567
htaccess redirect that request to
http://www.blabla.com/check.php?file=videos/1.mpg&hash=12345&expire=1234567
but also if someone type
http://www.blabla.com/videos/1.mpg
it is also redirect to check.php
http://www.blabla.com/check.php?file=videos/1.mpg
RewriteCond %{QUERY_STRING} ^hash=(.*)$
RewriteRule ^(.*)/videos/(.*)$ /check.php?file=videos/$2 [R=302,L,QSA]
Now your rewriteRule will only be applied if query string contains hash=xxxxx
use R=301 if you want users to be redirected permanently