Reputation: 266
Please I'm facing some challenges with my URL rewriting.
I'm trying to rewrite:
domian.com?v=subj to domian.com/subj
and domian.com?v=subj&id=3 to domian.com/subj/id
So users can directly access a clean URL.
Here's what I tried that wasn't working:
RewriteCond %{QUERY_STRING} ^v=(.*)$
RewriteRule ^index.php/?$ $1? [NC]
I also tried this too:
RewriteRule ^(.*)/([0-9])$ http://domain.com/$1/$2 [NC]
Both were not working. Please I need some clarification on this. Thanks.
Upvotes: 1
Views: 143
Reputation: 41249
You can use the following 2 rules to redirect query strings to SEF format.
RewriteEngine on
#--Redirect "?v=foo&id=bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php\?v=([^&]+)&id=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [NC,L,R]
#--Rewrite "/foo/bar" to "?v=foo&id=bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?v=$1&id=$2 [NC,QSA,L]
Upvotes: 2