Forum Moderators: phranque

Message Too Old, No Replies

simple modrewrite question

changing url path

         

johnquest

2:57 am on Jan 5, 2007 (gmt 0)

10+ Year Member



I need help in changing part of a URL with another word. What I have is www.mysite.com/foo/number and what I'd like is something like www.mysite.com/bar/number. Everything in the URL is the same except for changing "foo" to "bar" Can someone help me out?

Thanks

phranque

5:20 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i assume by "number" you mean digits.
you might try something like this:
RewriteCond %{ENV:myURI} ^(www\.mysite\.com/)foo(/[1-9]+)$ [NC]
RewriteRule . - [E=qRed:yes,E=myURI:%1bar%2]

jdMorgan

6:36 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

RewriteRule ^foo/([0-9]+)$ http://www.example.com/bar/$1 [R=301,L]

If you request example.com/foo/411 with that code in place, your browser will be redirected to example.com/bar/411

We're assuming you've got the RewriteEngine enabled here.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim