Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture end of URL

Status
Not open for further replies.

lagc

Programmer
Jan 21, 2009
79
GB
Hello all,

I have just translated a complete English site into a German site, its identical, appart from the translations, but they are using 2 different URL's.

What I'm tying to do, is capture everything after .com into a variable, so I can add it to the German flag which will then take that person to the exact page but with .de in front of it.

eg.


grabs everything after .com/ in a variable so I can have the exact same page accessed but in the german version through a german flag.


Cheers
 
mod_rewrite might be better for you.
are all url's fully qualified on your site?
 
Hi jpadie,

yes they are.

Basically it would be easier if I could grab everything after the last '\' into a variable, and I could use that.

I'm sure I have used it before, but it must have been so long ago, that I'm either wrong or forgotten it.

 
this should redirect .com to .de
Code:
if (false != strpos($_SERVER['REQUEST_URI'], '.com')):
  header ('Location: ' . str_replace('.com.','de', $_SERVER['REQUEST_URI']);
endif;

but i think that mod_rewrite would be better. for help on that please check out the apache forums on this site.
 
Thanks jpadie,

Could you help me some more please, as I'm not sure sure how to use that code properly.

I have created a button on each page in the form of a german flag, and when clicked it needs to use that code to direct the customer to the German page equivelant.

Could you show me please.

Thanks
 
ah. I see.

i think you should do something like this then.

Code:
<form method="post" action="">
<input type="hidden" value="<?php echo $_SERVER['REQUEST_URI'];?>" name="pageLink"?><input type="hidden" name="lang" value="de" /><input type="img" name="langSelect" src="path/to/german/flag" />
</form>

then create a page called langSelect.php
Code:
if (isset($_POST['langSelect']) && $_POST['langSelect'] == 'de')):
  if (false != strpos($_POST['pageLink'], '.com')):
    header ('Location: ' . str_replace('.com.','de', $_POST['pageLink']);
    exit;
  endif;
endif;

and at the top of every page that you wish to be language dependent add this code
Code:
<?php require_once '/path/to/langSelect.php'; ?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top