0

I would like to create a basic URL rewrite using frames.

I don't have access to .htaccess to do mod_rewrite.

Is there a way using PHP, jQuery, JavaScript etc. to detect which URL has been clicked on and then open URL in new frame?

Ex: user clicks on /index.php?12345 it will open in framed window /pages/12345/index.html and if they click on /index.php?54321 URL will open in framed window /pages/54321/index.html

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
  • I don't need all the pages re-written so something really basic would work. ie. In PHP get url selected if url= domain1 load urlA elseif url= domain2 load urlB –  Oct 04 '09 at 16:08

5 Answers5

1

I don't think I really understand what you mean. Usually url rewrite works like this:
User clicks on http://example.com/content/example
Which is the rewritten to http://example.com/index.php?cat=content&page=example

You can somewhat fake this effect by making your links into http://example.com/index.php/content/example the webserver will still request the page index.php, in which you can then read the part after index.php (but before a query string) with

$_SERVER['PATH_INFO']

and then parse that to get what you need.

PHP.net on $_SERVER['PATH_INFO']

Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.

Pim Jager
  • 31,965
  • 17
  • 72
  • 98
1

A PHP solution would be something along these lines:

if (!empty($_REQUEST)) {
    $page = array_pop($_REQUEST);
    if (is_numeric($page)) {
        header("Location: pages/$page/index.html");
        exit;
    }
}
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
0

If I've really understand what you want, I think it's easy.

When the user clicks it calls a JQuery function which sends the content of the link to PHP with AJAX. After that, PHP analyses the link, gets the content of the page (with include()) and sends that to JQuery via JSON.

k4nar
  • 301
  • 2
  • 6
0

Such jquery might help,

jQuery(function($){
  //this prevents all link elments' default behaviour 
  //when you click they won't navigate the page
  $("a").click(function(){
    //you get the links href
    var actual_url = $(this).attr("href");
    var new_url = "";
    //[write your code here for converting actual url to new one]
    //and open the new url in the frame you want
    window.parent.yourFrameName.location = new_url;
    //necessary for preventing default behaviour
    return false;
  });
});

Sinan.

Sinan
  • 11,443
  • 7
  • 37
  • 48
  • do you have an example of basic code for converting url like i mentioned for php above? –  Oct 04 '09 at 16:28
0

Best solution is to use jquery to check if link was visited and then change link's target to _blank.

You could use plugin from this site: link text and then execute such code:

 $('a').visited(function () {
  $(this).attr('target','_blank');
});

I think it is what are you looking for.

pbrodka
  • 1,137
  • 1
  • 11
  • 23