Ad

How To Redirect WordPress URL To Base Url Without Parameter

- 1 answer

We are trying to redirect URL like http://example.com/gtsdsds8yz/x3idsdssq.php?wtb=hgtvsdsd-m3u To http://example.com

for that, we are using .htaccess like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^wtb=hgtvsdsd-m3u$ [NC]
RewriteCond %{HTTP_HOST} .*
RewriteRule ^gtsdsds8yz/x3idsdssq\.php https://example.com [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>


RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Ad

Answer

RewriteCond %{QUERY_STRING} ^wtb=hgtvsdsd-m3u$ [NC]
RewriteCond %{HTTP_HOST} .*
RewriteRule ^gtsdsds8yz/x3idsdssq\.php https://example.com [L,R=301]

This should redirect to the root, however, it won't strip the URL parameters, which I assume is your problem? But note that you are strictly missing the trailing slash after the hostname on the substitution string (the browser would need to correct this).

To remove the query string you need the QSD (Query String Discard) flag (Apache 2.4+). Or, if you are still on Apache 2.2 then append a ? to the end of the substitution string instead.

For example:

RewriteCond %{QUERY_STRING} ^wtb=hgtvsdsd-m3u$ [NC]
RewriteRule ^gtsdsds8yz/x3idsdssq\.php https://example.com/ [L,R=301,QSD]

Note that this should go before all the WordPress directives, at the top of your .htaccess file.

You will need to clear your browser cache before testing.

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

You have also placed your HTTP to HTTPS redirect in the wrong place. This needs to go at the start of the file as well - before the WordPress front-controller as it simply won't redirect your WP URLs.

Ad
source: stackoverflow.com
Ad