Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRohin Kansal
Courses Plus Student 642 PointsHow to redirect to new url?
Hi, I created a rewrite url from domain.com/user.php?u=username to domain.com/username but when someone visits domain.com/user.php?u=username the page doesnot show domain.com/username but when user visits domain.com/username, it works well. I want to know that how to automatically redirect domain.com/user.php?u=username to domain.com/username whenever user visits the oldurl.
1 Answer
Christian Andersson
8,712 PointsIn your user.php page:
$username = $_GET["u"];
header("Location: http://domain.com/" . $username);
die();
Rohin Kansal
Courses Plus Student 642 PointsRohin Kansal
Courses Plus Student 642 Pointsbut how will it get the user details?
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsWhat user details?
Rohin Kansal
Courses Plus Student 642 PointsRohin Kansal
Courses Plus Student 642 PointsI am creating user.php a profile page. When I put the redirect as suggested by you, it went into a redirection loop.
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsHmm, I'm confused.
It was my understanding that you were asking how to redirect a user from
domain.com/user.php?u=username
todomain.com/username
. The code I provided does exactly this. I'm not sure how it can end up in a redirection loop. I am also unclear on what "user details" you were referring to.Please provide me a more elaborate explanation and I'll do my best to assist :)
Rohin Kansal
Courses Plus Student 642 PointsRohin Kansal
Courses Plus Student 642 PointsI solved that issue. Thanks Andersson for your help :) I would like to take advice from you on how to start a project. Whenever I start a project, i get confused on what to do and how to do. Can you advice me how to become a good and a skilled developer?
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsWell I'm not exactly an expert, but what you should do is to make a thorough planning of what you are going to develop. Make a list of features and make a flow-chart of how the different features connect to eachother. Ask yourself exactly what you want to develop, and avoid just "jumping into" the development.
You probably have a "rough idea" of what you want to do, but when the time comes where the nuts have to fit the bolts you'd be prone to problems in your implementation or effieciency, etc.
The bigger the system, the more time you should spend on planning. If you make a simple 4-page website for example you really should spend at least 2-3 hours on planning. If you are making something more complicated you might need 2-3 days.
Take your time on it. Otherwise you will run into a problem with your design and you'll be forced to go back and re-program something.
Rohin Kansal
Courses Plus Student 642 PointsRohin Kansal
Courses Plus Student 642 PointsThanks for your valuable answer. I always jumped into programming without planning. :) Thanks