godrob Posted July 11, 2011 Share Posted July 11, 2011 Hi guys, I could really do with some help here please... I am replacing my website and need to redirect ALL urls that are this format: http://www.domain.com/profile.php?user=Fay123 to http://www.domain.com The profile name can be upper or lowercase and can consist of both characters and numbers. I have tried adding this to my .htaccess file: RewriteRule ^profile.php?user=(.*) http://www.domain.com ..but it doesn't work. Can any of you smart guys help me out here please. I have about 400 profiles indexed in Google that are don't want to lose. Thanks Rob Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/ Share on other sites More sharing options...
cags Posted July 11, 2011 Share Posted July 11, 2011 The first half of a RewriteRule is matched against the REQUEST_URI, the query string (part after the question mark) is not include in this. Why do you wish to redirect all profile page requests to the homepage? Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241287 Share on other sites More sharing options...
godrob Posted July 11, 2011 Author Share Posted July 11, 2011 Sorry I should have explained in more detail. I am building a new site on a new server and asking existing members of my old site to reregister on the new server. The CMS I'm using is totally diffferent, and so I wanted to redirect all old profile pages indexed by Google to the NEW homepage. Is this not really a good idea then? If it is viable can you please assist me with the code I need to achieve this? Regards Rob. Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241521 Share on other sites More sharing options...
cags Posted July 11, 2011 Share Posted July 11, 2011 Ahh, well given the fact that you do in fact want all the pages to end up at the same page, then yes, that does make a bit more sense. Something like this should do the job... RewriteCond %{QUERY_STRING} user=[a-zA-Z0-9_-]+ RewriteRule ^profile.php$ / [R=301,L] ... though by the sounds of it you don't even need that much, since you aren't actually using the username, is there a reason you are matching against it in the query? Can you not just redirect any requests to profile.php to the home page? Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241527 Share on other sites More sharing options...
godrob Posted July 11, 2011 Author Share Posted July 11, 2011 Cags, thank you so much... Yes, anything that has profile.php within the url should be redirected to the new homepage. so... do I simply need this: RewriteRule ^profile.php$ / [R=301,L] ...or am I missing something here? Appreciate your help with this Thanks Rob. Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241546 Share on other sites More sharing options...
cags Posted July 11, 2011 Share Posted July 11, 2011 Yup, that should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241559 Share on other sites More sharing options...
godrob Posted July 11, 2011 Author Share Posted July 11, 2011 Perfect! That worked. Appreciate your help with this, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/241659-htaccess-redirect-dynamic-profile-urls-to-homepage/#findComment-1241581 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.