Jump to content

Catch PHP URL


johnnyjohnny

Recommended Posts

Not quite, the site I am working on is complete Ajax based, and the problem I ran into is the back/forth button and bookmark will not function, so to correct that the server side is going to catch the "#" part and decide what to display, so sadly it has to be processed on the server side.

 

very weird...

but you can use JavaScript insted PHP...

use this code to print the url:

<script language="javascript" type="text/javascript"> 
document.write (document.location.href); 
</script> 

Link to comment
https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872351
Share on other sites

That's interesting, do you mind elaborate more on that more?

 

I'd recommend either using a $_GET var then, or using htaccess and modrewrite to just take whatever is after the slash

 

e.g. http://foo.com/additionalinfo

 

a combo of modrewrite and $_SERVER['REQUEST_URI'] should accomplish the same goal and actually look cleaner.

Link to comment
https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872371
Share on other sites

Something like this should do the trick.

 

Create a .htaccess file in the root directory of your website.  Within it's contents put the following:

 

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?pg=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?pg=$1

 

This code above does the following:

 

User accesses the page: http://foo.com/additionalinfo

The rewrite converts this page to: http://foo.com/?pg=additionalinfo

However the user doesn't see the conversion, it remains http://foo.com/additionalinfo to the user.

But PHP can now parse the variable by $_GET['pg'] (even though it doesn't appear to exist).

Link to comment
https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872380
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.