Blezz Posted March 5, 2011 Share Posted March 5, 2011 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 More sharing options...
harristweed Posted March 5, 2011 Share Posted March 5, 2011 Sessions? Link to comment https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183371 Share on other sites More sharing options...
johnny86 Posted March 5, 2011 Share Posted March 5, 2011 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 https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183373 Share on other sites More sharing options...
Blezz Posted March 5, 2011 Author Share Posted March 5, 2011 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 https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183391 Share on other sites More sharing options...
Blezz Posted March 5, 2011 Author Share Posted March 5, 2011 Also added this to my apache config <directory "/etc/apache2"> AllowOverride ALL </directory> Didn't help =/ Link to comment https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183395 Share on other sites More sharing options...
trq Posted March 6, 2011 Share Posted March 6, 2011 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.. Can you explain why that is the case? Link to comment https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183396 Share on other sites More sharing options...
Blezz Posted March 6, 2011 Author Share Posted March 6, 2011 Okay I got the rewrite working, now my problem is $_SERVER['REQUEST_URI']; isn't returning anything =S Link to comment https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183398 Share on other sites More sharing options...
Blezz Posted March 6, 2011 Author Share Posted March 6, 2011 Nevermind I got it all working Link to comment https://forums.phpfreaks.com/topic/229716-permanent-link-to-a-virtual-file/#findComment-1183402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.