0

I've been spinning my wheels for a month on the following problem. Nothing I have tried from reading lots of answers from here and on stack exchange about rewriting queries has worked. Google has cached many urls with query parameters and I've been trying to remove the query parameters from the urls. example:

https://circadian.com/blog/12-hour-shifts?tmpl=component&print=1&format=print 

I'm trying to get that re-written to

https://circadian.com/blog/12-hour-shifts 

Any help here would be appreciated.

Thanks

6
  • Do you want to redirect requests that contain query arguments, or perform an internal rewrite that strips those arguments? Can you describe your backend web app? What stack is it built upon? Commented yesterday
  • The backend is Joomla. Google indexed the blog posts with that query and we're trying to strip the arguments. No solution I've found have worked. Seems like I'm missing something stupid. Commented 21 hours ago
  • I assume your setup involves Nginx working together with PHP-FPM, right? You still haven't answered my question — do you want to redirect requests that contain query arguments to their argumentless versions, or perform an internal rewrite that strips those arguments? In the first case, I can't see why the suggested solution doesn't work for you (though I'd prefer using a "regexless" check like if ($is_args) { rewrite ... }). Could it be that incorrect page versions are cached in your browser? Try clearing the browser cache or using an incognito window to verify that. Commented 12 hours ago
  • In the second case, the task is more complicated, and internal rewrites most likely won't help. The thing is, Joomla probably determines the requested route and query arguments from the FastCGI REQUEST_URI variable, which, in turn, is defined in the fastcgi_params Nginx configuration snippet to be equal to the $request_uri built-in variable. Unlike $uri, this variable does not change during internal rewrites, so the only way to make Joomla ignore query arguments is to redefine the REQUEST_URI variable using the fastcgi_param directive after including the fastcgi_params file. Commented 12 hours ago
  • Additionally, keep in mind that 301 permanent redirects are usually cached by user browsers, while 302 temporary redirects (which I suggest using in this case) typically are not. Commented 12 hours ago

1 Answer 1

0

Is it like this?

if ($args ~ ".+") { rewrite ^(.*)$ $scheme://$host$1? redirect; } 
2
  • I was hopeing that worked, but the print dialog still fires when I land on it. At least on the ipad. I'm seeing the rewrite happen in Firefox on Linux and even brave, palemoon and chromium. It still fires on Firefox on my mac. I'm totally stumped. I've tried just about everything that I've found in answers here and on substack. I've also tried: ``` location ~ ^/blog/(.*)/ { return 301 $scheme://$host/blog/$1?; } ``` Commented 2 days ago
  • There is no need using regex to check query arguments existence: if ($is_args) { ... } Commented 12 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.