1

How can I alter url or part of it using php? I lost the code that I have used and now I cannot find answer online.

I know using header('Location: www.site.com') gets redirect but how can I just show fake URL?

I don't want to use mod_rewrite now.

5
  • 1
    You have to dramatically improve your question, adding background story and particular example of what you want to get. Otherwise it will be closed. Commented Feb 25, 2011 at 10:07
  • 2
    So for example you want the user to be on www.fakebank.example.com but think they're on www.theirbank.example.com? Not a chance, sorry. Commented Feb 25, 2011 at 10:12
  • 1
    Do you want to become hacker? Commented Feb 25, 2011 at 10:15
  • 1
    Btw, the Location header takes the protocol, www.site.com will redirect to yourdomain.com/www.site.com ;-) Commented Feb 25, 2011 at 10:36
  • you can only do this on the host of a computer, hosts file and what not. Commented Feb 25, 2011 at 10:37

4 Answers 4

0

It is impossible in PHP, which is executed server side. Any change to the url you make will trigger a page loading.

I think it may be possible in javascript, but I really doubt this is a good idea, if you want to rewrite an url only in the user adressbar, you're doing something wrong, or bad ;)

Sign up to request clarification or add additional context in comments.

2 Comments

No i am just trying to not use mod rewrite and rather make seo friendly url with php... it hink it woked once i might be wrong. You know like with mod_rewrite there is way to show one extension like index.html but feed from index.php i looking to do same with php
is catching '404-page not found' what you think of? (in the sense of redirecting the 'page' not found to a controller)
0

What you've actually asked for isn't possible in using PHP (Although, in JavaScript you can use the dreadful hashbang or the poorly supported bleeding edge pushState).

However, in a comment on another answer you stated that your goal is actually friendly URIs without mod_rewrite. This isn't about showing a different URI to the real one, but about making a URI that isn't based on a simple set of files and directories.

This is usually achieved (in PHP-land) with mod_rewrite, so you should probably stick with that approach.

However, you can do it using ScriptAlias (assuming you use Apache, other webservers may have different approaches).

e.g. ScriptAlias /example /var/www/example.php in the Apache configuration.

Then in the PHP script you can read $_SERVER['REQUEST_URI'] to find out what is requested and pull in the appropriate content.

Comments

0

You can make somewhat SEO-friendly URLs by adding directories after the php script name so that your URLs become:

http://yoursite.com/script.php/arg1/arg2

In script.php:

<?php

$args = preg_split('#/#', $_SERVER['PATH_INFO']);

echo "arg1 = ".$args[1].", arg2 = ".$args[2]."\n";

?>

if you use some more htaccess trickery, then you can make the script.php look like something else (see @David's answer for an idea)

Comments

0

You can try using,

file_get_contents("https://website.com");

This is not going to redirect but fire the api and you can catch the output by assigning a variable to above function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.