hgwd92
hgwd92

Reputation: 69

Change URL with rewrite rule

How can I change my URL from domain.com/sprekers/?spreker=value to domain.com/value with a rewrite rule with wordpress.

I've tried to change it like this

RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]

than I tested it with the htaccess tester http://htaccess.madewithlove.be If I test it on the tester everything works fine but when I do this on my wordpress site it doesn't work. This is my complete htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
</IfModule>

I think it doesn't work because the /sprekers is already "made" by wordpress how can I fix this?

Cheers Robin

Upvotes: 0

Views: 83

Answers (1)

Im ieee
Im ieee

Reputation: 469

I think, you need to put your first code after the RewriteBase / rule.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Upvotes: 1

Related Questions