1

I'm rebuilding a site in wordpress. The existing site has unique profile pages with the URL of the form www.domain.com/b/ch/2lZl.htm

The new system will have unique profile pages of the form www.domain.com/profile/bch2lZL (where bch2lZL is the unique user ID).

What I need to do is get this unique ID and load the page www.domain.com/tracker/public/user/bch2lZL which will do the processing (load in content for this user etc) but don't want the URL to change from www.domain.com/profile/bch2lZL.

I'm hoping this can be achieved with a htaccess redirect where it can load the user can go to the domain www.domain.com/profile/bch2lZL and be presented with the page which is actually at www.domain.com/tracker/public/user/bch2lZL without a change in the URL

Is this possible? And how can I do it?

Cheers in advance

nvaughan84
  • 463
  • 6
  • 13
  • This isn't called "redirecting". It's called "rewriting". Pretty simple if you do some research and actually try something. – HamZa Nov 20 '14 at 10:43
  • 1
    possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – HamZa Nov 20 '14 at 10:44

1 Answers1

1

This can be done with RewriteRule in htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/b/ch/(.*).htm$ www.domain.com/profile/$1 [R=301,L]
Wobbles
  • 3,033
  • 1
  • 25
  • 51
  • That's great, thanks Wobbles. I'm using the rule `RewriteRule ^[a-z]{1}/[a-z]{2}/([0-9]+).htm /profile/$1 [P,L]`. The problem is, with the brackets around [0-9]+ it causes the page to redirect (rather than keeping the URL). Is there a way to pass the variables without changing the URL? Also, adding brackets around `[a-z]{2}` and `[a-z]{1}` (to use as variable in the second URL) stops the match from working – nvaughan84 Nov 20 '14 at 12:21
  • Wrap any expression you wish to reuse in parentheses then access it in the url with a base 1 index, so $1 $2 $3 etc... – Wobbles Nov 21 '14 at 12:41