October 7, 2012

Use PHP to rewrite the address bar?

Question by Hoser

Maybe I’m going about this the wrong way, but I’ll lay out the process I’d like my website to perform and then see what solutions you guys can think of.

At the URL

example.net/ShellySite/Form/form.php

There is a form to be filled out, then a submit button is pressed, and the website goes to

example.net/ShellySite/Controller/PHP/submitform.php

It goes here because it submits the details in the form to a database, what I’d like to do is basically instantly reroute the browser to a different page after the code at the submitform.php page has finished running, something like

example.net/ShellySite/Home/home.php

But I can’t seem to get it to work. I’ve tried stuff like header(Location:"example.net/ShellySite/Home/home.php")
but it just appends all that onto the end of example.net/ShellySite/Controller/PHP/submitform.php, and that obviously isn’t what I want.

Any help would be great!

Answer by deceze

Use absolute URLs:

header('Location: http://example.net/ShellySite/Home/home.php');

Answer by Starx

Rewriting can be done with .htaccess what you are looking for in redirection.

Since, you are trying to use absolute URLs, You are missing protocol in your request. Like http and https. Add them

header('Location: http://example.net/ShellySite/Home/home.php');
exit; // Dont forget to add this

Or use relative URLs like

header('Location: /ShellySite/Home/home.php');
exit;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!