kevinlcarlson Posted November 2, 2009 Share Posted November 2, 2009 I'd like for users to be able to pass URL parameters simply, for example instead of www.mysite.php?id=12345 I'd like to allow them to type www.mysite.php/12345 I've seen this done on a few sites, and wonder whether there's some way for PHP to process it? Would this method involve .htaccess, etc.? Maybe it intercepts 404 error conditions? Thanks! Kevin Link to comment https://forums.phpfreaks.com/topic/179895-simplified-url-parameter-passing/ Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 Hi Kevin, This would be handled by .htaccess. # Enable mod_rewrite, start rewrite engine RewriteEngine On RewriteRule (.*)/$ index.php?id=$1 RewriteCond %{HTTP_HOST} !^(.*)\.mysite\.com$ [NC] RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] Link to comment https://forums.phpfreaks.com/topic/179895-simplified-url-parameter-passing/#findComment-948991 Share on other sites More sharing options...
kevinlcarlson Posted November 2, 2009 Author Share Posted November 2, 2009 Wow, thanks for the tip! I hadn't seen Rewrite used before! I also came across ErrorDocument 404 /process/404err.php which treats the url parameter as an unknown web page and redirects for processing. The passed parameter can then be extracted as substr($_SERVER["SCRIPT_URL"],1) for processing. I'll try both approaches to see what works best for this situation... For security purposes, I wonder if it's possible to simultaneously prevent users from directly accessing a redirect directory by using a 403 handler? I tried restricting the subdirectory access to only allow requests from the server's own IP address, but this blocked everything. Or, maybe I should just use IndexIgnore * to hide everything from hackers, bots, etc.? Thanks again, Kevin Link to comment https://forums.phpfreaks.com/topic/179895-simplified-url-parameter-passing/#findComment-949757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.