Reputation: 21
I tried a lot of code without results. I'm using wordpress and the url of search results is:
http://mysite.com/search/the%20search%20query%20
I need to change it in
http://mysite.com/search/the-search-query/
Is there a way with htaccess?
This is actually my htaccess file:
# 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>
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# END WordPress
The last rewrite rule is what i trie without success
Upvotes: 1
Views: 2413
Reputation: 143886
Your rule looks fine, however you have it after your routing rules. That means no matter what, that rule will never be reached because everything, including any request with a space in it, gets routed to index.php
. You need to put any redirect rules before your routing rules:
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# 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
Upvotes: 2