mosidiot Posted October 18, 2010 Share Posted October 18, 2010 Hi, how to let php read the url in folder form instead of querystring? e.g. www.example.com/index.php?post=123 www.example.com/post/123/ both is actually directed to the same page - index.php, but how to make it read like a folder when the physical path doesn't really exist? Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/ Share on other sites More sharing options...
objnoob Posted October 18, 2010 Share Posted October 18, 2010 Manipulate a string? $folder_name = 'www.example.com/post/'.$_GET['post']; If your index.php always expects a value in the URL named post... Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/#findComment-1123280 Share on other sites More sharing options...
chintansshah Posted October 18, 2010 Share Posted October 18, 2010 You can do this using htaccess rewrite rule, Please googling, you will find the solution. Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/#findComment-1123282 Share on other sites More sharing options...
objnoob Posted October 18, 2010 Share Posted October 18, 2010 Yeah I figured he wanted apache's mod_rewrite, but how does one get access to the index.php of www.example.com/post/123/ if the physical path doesn't exist, and no rewrite rules are in use. Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/#findComment-1123285 Share on other sites More sharing options...
Buddski Posted October 18, 2010 Share Posted October 18, 2010 Quote Yeah I figured he wanted apache's mod_rewrite, but how does one get access to the index.php of www.example.com/post/123/ if the physical path doesn't exist, and no rewrite rules are in use. The idea of a mod_rewrite is so when a user types in the address http://www.example.com/post/123/ it will be "re-written" to be whatever the mod_rewrite rule tells it. Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/#findComment-1123289 Share on other sites More sharing options...
mosidiot Posted October 18, 2010 Author Share Posted October 18, 2010 Thanks guys! objNoob, Thanks, thanks a good solution, I see websites or CMS software did something like that without htaccess rewriterule I realized using htaccess utilized less resources and faster. Thanks a lot for your solution anyway! I will use it when I need to bypass apache mod or probably in IIS host. Buddski Yup, thanks.. Google indeed helps! I wasn't sure what kind of term it used for this kind of redirection. Example is as follows: Options +FollowSymlinks RewriteEngine on RewriteRule ^products/([^/]+)$ index.php?prodID=$1 Thanks guys for the kind help! Really appreciated that. Quote Link to comment https://forums.phpfreaks.com/topic/216139-php-read-url-in-folder-form-instead-of-querystring/#findComment-1123314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.