Issue with nginx rewrite rule for wordpress default search query - wordpress

I'm using nginx and I found some 404 errors for WordPress blog searches. I need to make a rewrite in nginx but I need help to do.
Eg:
404 URL
http://example.com/blog/?s=searchterm
Should be redirected to
http://example.com/?s=searchterm

Related

How to redirect whole domain to a single Wordpress page with Nginx

I have a Wordpress website, installed on domain1.com, where I need to redirect all domain2.com traffic to a domain1.com/somepage page.
I have an http-to-https redirect in place (automatic from certbot) and the default wordpress nginx configuration, and everything works fine with a domain mapping plugin: https://domain2.comcorrectly shows https://domain1.com/somepage keeping the original url.
The problem is that https://domain2.com/somethingelse should always redirect to https://domain1.com/somepage, as of now it redirects to the Wordpress 404 page (which is on domain1.com.
I've tried fiddling with redirects and rewrites in nginx, the best result was a redirection loop:
if ($host = domain2.com){
rewrite ^/(.+)$ / last;
}
How can I achieve full domain redirection?
I solved it by using another Wordpress plugin: Redirection.
I just set a redirect for /.+ matching the Host:domain2.com header to https://domain2.com.
Multiple domain mapping plugin takes care of mapping domain2.com to the correct page.

If the page 404s, then 301?

On a wordpress site.
I'm updating the permalinks so that the posts go to /blog/title-of-post instead of right off the route. Problem then becomes all 400+ posts that are on the site will 404.
Rather that add a 301 redirect in the htaccess file for each of these, is there a better way?
Can I set the htaccess to detect the url, and if it 404s, to instead send the traffic to url.com/blog/the-rest-of-the-title, so that it passes the same url string but with /blog/ in front of it?
Hope this is clear, please let me know if there's any questions.
Thanks in advance/
this is possible only on apache 2.4+ . On apache 2.4 you can pass the 404 URI string to the destination url of ErrorDocument.
ErrorDocument 404 http://example.com/blog%{REQUEST_URI}
This example will not work on lower versions of apache as they dont understand the %{SERVER_VARIABLE}

redirects issue in wordpress multisite

Recently I configured my website for https and redirected http to https but now in google page speed, I am getting issue of Too many redirects!
Can be checked at: https://developers.google.com/speed/pagespeed/insights/?url=peterkentconsulting.com&tab=desktop
And Google explains: Your page has 2 redirects, site is wordpress multisite. Please help me to remove those redirects..
Thanks
Your http to https redirect is not working fine. You should configure all urls:
http://peterkentconsulting.com/
http://www.peterkentconsulting.com/
http://www.peterkentconsulting.com/index.php
to
https://www.peterkentconsulting.com/
Now as I see your site's all requests are first going to /index.php which wordpress redirects to / in its .htaccess.
You should directly redirect http://www.peterkentconsulting.com/ to https://www.peterkentconsulting.com/
solved by editing site url at wp_site and wp_options tables in database.

301 and HTTPS redirect to root via htaccess

I moved domain from http to https. And currently all http urls are redirected to https.
But there are some broken links from old urls such as http://domain.tld/url-link-broken and I would like to redirect them to the root domain.
The problem is that currently http://domain.tld/url-link-broken redirects to https://domain.tld/url-link-broken
How can I change this via htaccess so that if url is broken it would not only redirect to https but also to the root?
Check following things first
Your console gives any error there regarding resources
Check do you have static links in menu or anywhere else
Check your home_url and site_url in admin
Solution
Using Plugin:
Please Take Backup of database before proceed
https://wordpress.org/plugins/ssl-insecure-content-fixer/
For More Information :
https://managewp.com/wordpress-ssl-settings-and-how-to-resolve-mixed-content-warnings

301 redirections when migrating from Wordpress to Ghost

I want to migrate my WP blog to ghost, the permalinks have the same slug (/blogWP.com/title-article and blogGhost.com/title-article) but I still have pages such as blog.com/category for instance to redirect.
Is there any way to make 301 redirections in Ghost as I would do in a .htaccess file ?
Thx !
It's possible to redirect through ghost itself directly, but you need to alter the core. Though I'm not sure it's the perfect or proper way.
open core/server/errorHandling.js
find this line:
error404: function (req, res, next) {
Add below:
res.status(301);
res.set({'Location': 'http://your-new-wordpress-blog-url'+req.url});
res.send('301','Not found');
This way, Instead of showind 404s, I redirect to my wordpress' new domain (http://your-new-wordpress-blog-url in the example)
This way, www.ghost.url/not-a-valid-page will redirect to http://your-new-wordpress-blog-url/not-a-valid-page instead of showing the Ghost's 404 page.
p.s: This redirects, but I'm not 100% sure the headers are correct, I'd appreciate if someone else would clarify.
I'm sorry, but there is currently no way to do redirects with Ghost.
The best way to do redirects is to use a proxy server (recommended) and do the redirects there. For Apache you could use .htaccess files and nginx offers HttpRewriteModule.
My ghost blog is a subdirectory /blog/ runing with NGINX.
I needed to redirect old wordpress urls /blog/category/post-title to /blog/post-title
Except for /blog/ghost/.., /blog/tag/.., /blog/author/.., /blog/post-title/amp/.
So I came with that rewrite rule :
rewrite ^/blog/(?:(?!ghost|tag|author).).*/(?:(?!amp))(.+)$ /blog/$1 permanent;

Resources