Reputation:
I would like to redirect, for example :
index.php?name=sarah
to
names/sarah.php
The folder structure:
I've tried :
RewriteRule index.php?name=$1 /names/$1.php
and other ones, but didn't came to a solution.
Is this possible? If so, how can you do this?
Note:
The other way round is
RewriteRule ^names/([^/]*)\.php$ index.php?q=$1 [QSA,L]
which works fine.
Upvotes: 0
Views: 35
Reputation: 41219
You first example wont work as you are trying to manipulate query strings using a RewriteRule but this is not allowed. You can try the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} / index\.php\?q=([^\s]+) [NC]
RewriteRule ^ /names/%1.php? [L,R]
RewriteRule ^names/([^/]*)\.php$ index.php?q=$1 [QSA,L]
Upvotes: 1
Reputation: 5748
Here is your rule:
RewriteCond %{QUERY_STRING} name=([^&]*)
RewriteRule ^.*$ /names/%1.php?
Upvotes: 1