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
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.

Link to comment
Share on other sites

Okay so after looking at a tutorial I came up with this as my .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z-]*).html /index.php?username=$1

but it is still giving me 404 =/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.