Jump to content

Permanent link to a 'virtual' file?


Blezz

Recommended Posts

Alright so I'm going to try to explain this as best I can..

 

Basically right now to access a specific row in a DB the url is ?id=1

The page uses the $_GET to search for the row where id=1, blah blah blah

 

But I have another script that cannot use ?id= on url, it needs to be a static url like index.php or /dir/ or index.html, if that makes sense..

So if I had a url index.php?id=1 the script only allows index.php, thus it doesn't find the right content because without the ?id it just shows all rows, not that specific one..

 

So basically I need some way to make a virtual link, for example test.com/id/1  do the same as index.php?id=1 without actually creating hundreds of dir's and pages =/

 

Any ideas? A lot of bigger websites do this but I'm not sure how so any help would be greatly appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/
Share on other sites

Mod_rewrite is what you are looking for.. if you are using apache.. example .htaccess:

RewriteEngine On

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

 

Then in your PHP code you'll have to parse your request parameters from $_SERVER['REQUEST_URI'] etc.

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.