Reputation: 235
I try to re-write a URL that have this form:
website.com/?q=home
to this form:
website.com/home
I cannot find.
I tried this form for example: RewriteRule ^\?q\=home$ /home [R=301,L]
Looks like the "?" or the "=" are posing problem? Can you help me?
Thank you
Upvotes: 0
Views: 246
Reputation: 63566
Everything after the ?
is in the variable %{QUERY_STRING}
.
To rewrite just the value home
use:
RewriteCond %{QUERY_STRING} ^q=home$
RewriteRule ^ /home? [L,R=301]
To rewrite all q
values to static URIs use:
RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^ /%1? [L,R=301]
The last ? in the RewriteRule removes the query string from the target URI.
Reference: Apache mod_rewrite
Upvotes: 1