Tzar February 2016

Wordpress URL - Need to remove a GET parameter

I know there are a lot of threads for .htaccess URL rewriting, but my case seems to be a bit different and I have tried a lot but it doesn't work.

My current URL: http://example.com/forest/trees/?type=perennial

What I need is: http://example.com/forest/trees/perennial

I just need to remove the ?type= from the URL.

EDIT: The URL may contain hyphens - between strings at any point (except the domain name ofcourse). It can be dense-forest or non-perennial too.

It's a custom code and plugin, so can't modify it. I just need the URL beautified.

Any help would be greatly appreciated.


What I've tried so far in .htaccess:

RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /forest\/trees\/\?type=([^&]+)
RewriteRule ^ \/forest\/trees\/%2\/? [L,R=301]

and

RewriteRule ^\/forest\/trees\/([^/]*)?  /forest/trees/?type=$1 [L]

My current Wordpress .htaccess is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Thanks in advance. :) Cheers!

Answers


Florian Lemaitre February 2016

You can use this .htaccess file:

# BEGIN WordPress
RewriteEngine On
RewriteBase /

RewriteRule ^forest/trees/([^/]+)$ /forest/trees/?type=$1

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

Now URLs like http://example.com/forest/trees/perennial will internally redirect to /forest/trees/?type=perennial and then to Wordpress Dispatcher /index.php.

Post Status

Asked in February 2016
Viewed 3,357 times
Voted 7
Answered 1 times

Search




Leave an answer