Forum Moderators: coopster

Message Too Old, No Replies

(basic) Help find redirect rule for this using htaccess

         

basketmen

1:00 pm on Jan 30, 2010 (gmt 0)

10+ Year Member



it is very simple actually, i just want redirect all pages from old username url to new username url

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]

rocknbil

8:15 pm on Jan 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Posting a link to this in the community forum, changes made to the system recently have made this hard to figure out from what you posted there. (Others viewing, mouse over the links, look at status bar . . . )

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 . . .