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 trial

PHP

Rohin Kansal
PLUS
Rohin Kansal
Courses Plus Student 642 Points

How 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

In your user.php page:

$username = $_GET["u"];
header("Location: http://domain.com/" . $username);
die();

What user details?

Rohin Kansal
Rohin Kansal
Courses Plus Student 642 Points

I am creating user.php a profile page. When I put the redirect as suggested by you, it went into a redirection loop.

Hmm, I'm confused.

It was my understanding that you were asking how to redirect a user from domain.com/user.php?u=username to domain.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
Rohin Kansal
Courses Plus Student 642 Points

I 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?

Well 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
Rohin Kansal
Courses Plus Student 642 Points

Thanks for your valuable answer. I always jumped into programming without planning. :) Thanks