Jump to content

simplified url parameter passing


kevinlcarlson

Recommended Posts

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

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]

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

 

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.