I use directive .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)appId=
RewriteCond %{QUERY_STRING} !(^|&)q=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>
The problem would be solved if this RewriteCond %{QUERY_STRING} !^$
replace with this RewriteCond %{THE_REQUEST} \?
But this directive does not work on the Litespeed server. That's for sure, I contacted the developers of this server.
How to cut (redirect) to a link without a question mark via function.php?
example: if open website/post-name.html? >>>redirect>>> website/post-name.html
Sorry for my English.
I use directive .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)appId=
RewriteCond %{QUERY_STRING} !(^|&)q=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>
The problem would be solved if this RewriteCond %{QUERY_STRING} !^$
replace with this RewriteCond %{THE_REQUEST} \?
But this directive does not work on the Litespeed server. That's for sure, I contacted the developers of this server.
How to cut (redirect) to a link without a question mark via function.php?
example: if open website/post-name.html? >>>redirect>>> website/post-name.html
Sorry for my English.
Share Improve this question asked Jan 3, 2022 at 21:19 UserUser-nameUserUser-name 577 bronze badges 4 |1 Answer
Reset to default 1Try this, which uses the parse_request
hook: (you can add other conditions, e.g. check whether $wp->query_vars['name']
is not empty, if you want to)
add_action( 'parse_request', 'wpse_400900_parse_request', 1 );
function wpse_400900_parse_request( $wp ) {
// Redirect if the URL ends with a ? like https://example?
if ( ! empty( $_SERVER['REQUEST_URI'] ) &&
ltrim( $_SERVER['REQUEST_URI'], '/' ) === "{$wp->request}?"
) {
wp_redirect( home_url( $wp->request ) );
exit;
}
}
?
, i.e. no query string parameters specified? 3. What exactly are you trying to do? Why do you need to cut the?
? What does doing that solve? – Sally CJ Commented Jan 4, 2022 at 3:42User-agent: Yandex Disallow: /*?$
? You may also find something helpful here. – Sally CJ Commented Jan 4, 2022 at 13:29