Forum Moderators: coopster
please help what is the right htaccess rule for this Guys
i want to redirect old url
http://www.example.com/r/folder1/?do=view&vidid=username
to new url
http://www.example.com/r/folder2/username.html
so example old url is
http://www.example.com/r/folder1/?do=view&vidid=michael
to new url
http://www.example.com/r/folder2/michael.html
[edited by: tedster at 1:18 am (utc) on Jan. 31, 2010]
[edit reason] swith to example.com - it cannot be owned [/edit]
The first thing - you appear to be making a common mistake, and that is getting your rules backwards. You don't write ugly_long_query_string -> friendly_url, you write friendly_url -> ugly_long_query_string. The friendly_url is what stays in the address bar.
This is not a "working solution" but a best guess - it might work "as is" but may have errors. Give it a shot.
(html)
<a href="/r/folder2/michael.html">Michael</a>
(.htaccess)
<IfModule mod_rewrite.c>
RewriteEngine On
rewrite_rule ^/r/folder2/([a-z0-9\_\-]+)\.html$ /r/folder1/?do=view&vidid=$1 [NC,L]
</IfModule>
The NC makes it case insensitive, the L is last rule to process, not needed if it's the last rule or only rule in the .htaccess. Whatever is in () is stored in $1, hence "michael.html" -> vidid=michael. As you see, I have added other possible characters numeric 0-9, - and _ , if these are not allowed and are filtered in user name creation, just delete them: [a-z]+. A-Z is not needed, see NC above.
However, better yet, why don't you do THIS?
(html)
<a href="/members/Michael">Michael</a>
(.htaccess)
<IfModule mod_rewrite.c>
RewriteEngine On
rewrite_rule ^/members/([a-z0-9\_\-]+)$ /r/folder1/?do=view&vidid=$1 [NC,L]
</IfModule>
Much "prettier" and easier to remember . . .