How to change url in php

I want to change the URL through PHP.

Something like window.location.href = "http://www.something.com" in JavaScript.

I want the same thing but in PHP. How can I do it?

How to change url in php

asked May 4, 2010 at 9:57

1

You can use the header function for that:

header("LOCATION: http://www.something.com");

answered May 4, 2010 at 9:59

How to change url in php

SarfrazSarfraz

371k73 gold badges529 silver badges574 bronze badges

0

You could use the header() command:


answered May 4, 2010 at 10:00

richsagerichsage

26.7k8 gold badges57 silver badges65 bronze badges


Make sure there is nothing above the line outputted, otherwise it will fail.

TimWolla

30.9k8 gold badges64 silver badges94 bronze badges

answered May 4, 2010 at 10:00

GlycerineGlycerine

6,8543 gold badges38 silver badges63 bronze badges

1

You could use ob_start along with the header function in order to prevent redirection errors like so:


answered Sep 25, 2016 at 23:03

How to change url in php

MysticalMystical

2,1952 gold badges21 silver badges35 bronze badges

1

You have to create a .htaccess file using an editor like notepad or notepad++, before that you should activate the rewrite option in httpd.conf.
Use this link to understand how to activate this

Jump to Post

you mean there's an htaccess already and it's ruining the normal operation? because if there's no htaccess, then the path /htdocs/emp/emp.php will be viewed in http://localhost/emp/emp.php, take note of the folder "emp".

Jump to Post

All 6 Replies

How to change url in php

How to change url in php

How to change url in php

10 Years Ago

you mean there's an htaccess already and it's ruining the normal operation? because if there's no htaccess, then the path /htdocs/emp/emp.php will be viewed in http://localhost/emp/emp.php, take note of the folder "emp".

How to change url in php

10 Years Ago

I understand that you don't have a htaccess file in your folder with the project emp and you want to redirect localhost tolook like http://localhost/emp.php.
To do that you will have to use my first post and enable htaccess using that and then you will have to change some settings in your xampp.
Xampp is known for it's problems like when you type just localhost it will go to the index of xampp not you custom index.
Hope that helps you,if not try to watch killerphp advanced php part 7 to understand htaccess.
Bye

How to change url in php

diafol

10 Years Ago

Edited 10 Years Ago by diafol because: n/a

How to change url in php

Reply to this topic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.

How can I change the current URL in PHP?

php if (! $_GET["name"] && $_GET["id"]) { // perform MySQL query to get name based on id header("Location: http://www.something.org/zzz"); die(); // stop execution of this page } // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do. ?> NOTE: The above .

How can I change URL without reloading page in PHP?

It will be helpful to understand the given script..
First of all, fire click event on the navigation link a. ... .
Prevent page refreshing using e. ... .
Get the Current URL by clicking a navigation link and store it in pageURL..
Change URL without reloading the page using history.pushState(null, '', pageURL).

How do I get the URL of a PHP file?

To get the current page URL, PHP provides a superglobal variable $_SERVER. The $_SERVER is a built-in variable of PHP, which is used to get the current page URL. It is a superglobal variable, means it is always available in all scope.

What is a PHP URL?

Definition of PHP URL. Generally, the URL means Uniform Resource Locater. Likewise, URL in PHP Programming Language is also the same. URL is nothing but a website address. It helps in connecting the client and the server when browsed using a specific link.