boyakasha Posted January 18, 2007 Share Posted January 18, 2007 I want to set up a website such that I create a file, let's say [color=red]/something/redirector.php[/color], that receives any url in the [color=red]/something/[/color] directory with the requested URL as an argument. For example, if the user requests [color=red]/something/action/variable[/color] then it calls [color=red]/something/redirector.php?path=/something/action/variable[/color] or something similar.It doesn't have to use GET variables, I just need the requested URL to be available to [color=red]/something/redirector.php[/color]. I had a look around the web and happened across mod_rewrite for Apache, which may be able to do it, but I was wondering if there was an easier way that anyone knew of. Link to comment https://forums.phpfreaks.com/topic/34699-urls-as-variables-to-a-php-script/ Share on other sites More sharing options...
GingerRobot Posted January 18, 2007 Share Posted January 18, 2007 As far as i am aware, this is a job for mod_rewrite. Link to comment https://forums.phpfreaks.com/topic/34699-urls-as-variables-to-a-php-script/#findComment-163540 Share on other sites More sharing options...
Devsense Posted January 18, 2007 Share Posted January 18, 2007 I want to set up a website such that I create a file, let's say /something/redirector.php, that receives any url in the /something/ directory with the requested URL as an argument. For example, if the user requests /something/action/variable then it calls /something/redirector.php?path=/something/action/variable or something similar.[b]/.htaccess[/b][code]option +followsymlinksRewriteEngine OnRewriteRule ^/something.*$ /something/redirector.php?path=$1[/code]I would imagine that rewrite rule would work. Don't hold me to it though ;). Link to comment https://forums.phpfreaks.com/topic/34699-urls-as-variables-to-a-php-script/#findComment-163678 Share on other sites More sharing options...
boyakasha Posted January 19, 2007 Author Share Posted January 19, 2007 Thanks for the replies. I had a better look at mod_rewrite and ended up "borrowing" settings from the ruby on rails .htaccess file. I ended up using:[code]<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ index.php [QSA] RewriteRule ^([^.]+)$ $1.php [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.php [QSA,L]</IfModule>[/code]Works like a charm. If a page doesn't exist, it gets redirected to dispatch.php and $_SERVER['REQUEST_URI'] is set to the requested URL. Link to comment https://forums.phpfreaks.com/topic/34699-urls-as-variables-to-a-php-script/#findComment-164308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.