Reputation: 1
I having a URL http://www.domain.com/postname/?a_different_world
I need to change it to http://www.domain.com/postname/a_different_world
How to remove ? from the URL using Htacccess(Wordpress)
I use following htaccess code. But it is not working
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php-$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /domain.com/index.php [L]
RewriteRule ^/postname/([0-9]+)$ /? $1 [L,QSA]
Upvotes: 0
Views: 227
Reputation: 10878
The rule match string strips out the query string (everything after the ?). Hence you want to drop the ? and explicitly use the query string like this (instead of your last rule)
RewriteCond %{QUERY_STRING} ^([\w\-]+)$
RewriteRule ^postname/$ postname/%1? [L]
Note that you should drop the leading / as this won't match as .htaccess rule match string drops the leading /; also note the ? in the replacement pattern and omission of the QSA flag as you don't want to append the query string.
Also move this rule above the previous cond/rule as this second rule will fire on your postname pattern so you'll never get to this rule unless you move it up one.
Upvotes: 1