DataRater Posted July 27, 2008 Share Posted July 27, 2008 Apache PHP funnelling I want to make Apache send all URLs to one index.php in the top directory called www say. So all PHP calls will be funneled into index.php. The directory structure so far is... www/index.php and in the Apache .htaccess or httpd.conf we have <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] </IfModule> That is going to send any URL to the index.php with any query string contained in $_GET['url']. Underneath that directory i want to put the js,ico,txt,gif,jpg,png,css filles in directories something like like this www/js www/pics // this is for the ico, gif, jpg, png files www/txt www/css How do I make the ReWrite do the complete job of funneling into index.php yet allow calls to the other files 'fall through'? Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/ Share on other sites More sharing options...
corbin Posted July 27, 2008 Share Posted July 27, 2008 RewriteEngine On RewriteRule ^(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] RewriteRule ^(.*)\.js /js/$1.js [NC,L] RewriteRule ^(.*)\.css /css/$1.css [NC,L] RewriteRule ^(.*)\.php$ /index.php?url=$1 [QSA] www/ is the web root right? Like if you went to http://yoursite.com/index.php, it would be showing www/index.php? That would redirect anything.ico or gif or jpg or png to /pics/<file>, and the same with JS and CSS files (to their corrosponding directories). Then, the last statement is what I would consider a catch-all that will forward anything else to index.php?url=<page>. Someone else will probably come up with a better way to do it though since my way isn't very efficient at all. Oh, I should also note, that JS/CSS/Image files with query strings will be redirected to index.php, not their folders. Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-600949 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 Hi Corbin, Thanks for that. You've definitely helped me and got some creative juices flowing. For the php part I want something along the lines of digg. http://digg.com/ So if you select 'Technology', you get a URL of http://digg.com/technology and it doesn't show the underlying technology. In my case I want that to go to index.php. Have you any idea how to adjust your solution so it follows the Digg pattern? Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601410 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 RewriteRule ^(.*)$ /index.php?url=$1 [QSA] This will pass everyting after the slash at the end of the domain name to the $_GET['url'] variable. Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601422 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 Hi Corbin and Thorpe, Sorry I didn't answer your question "www/ is the web root right?". Yes it is. :-) Maybe I should explicitely map each psuedo page to the index.php like this. I've used the pages as per digg. RewriteRule ^technology$ /index.php [L] RewriteRule ^gaming$ /index.php [L] RewriteRule ^science$ /index.php [L] But I do want to know what the orginating URL was and if there are any GET parameters so I think I should do this. RewriteRule ^(technology)$ /index.php?url=$1 [QSA][L] RewriteRule ^(gaming)$ /index.php?url=$1 [QSA][L] RewriteRule ^(science)$ /index.php?url=$1 [QSA][L] At least that way only pages I explicitely map get mapped. So this is what I've got now. RewriteEngine On RewriteRule ^(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] RewriteRule ^(.*)\.js /js/$1.js [NC,L] RewriteRule ^(.*)\.css /css/$1.css [NC,L] RewriteRule ^(technology)$ /index.php?url=$1 [QSA][L] RewriteRule ^(gaming)$ /index.php?url=$1 [QSA][L] RewriteRule ^(science)$ /index.php?url=$1 [QSA][L] Am I on the right track? Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601446 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 That should have been RewriteEngine On RewriteRule ^(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] RewriteRule ^(.*)\.js /js/$1.js [NC,L] RewriteRule ^(.*)\.css /css/$1.css [NC,L] RewriteRule ^(technology)$ /index.php?url=$1 [QSA,L] RewriteRule ^(gaming)$ /index.php?url=$1 [QSA,L] RewriteRule ^(science)$ /index.php?url=$1 [QSA.L] Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601568 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 I had to put a slash on the ReWrite to get it to work RewriteRule ^(technology)$ /index.php?url=$1 [QSA,L] became RewriteRule ^(technology/)$ /index.php?url=$1 [QSA,L] This images don't work and I have no understanding why. It definitely looks OK to me. I've checked the file and directory permissions and World has Read RewriteRule ^(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601611 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 I think Apache is not able to look in the pics sub-directory of the document root. Is there a command which forces it to stay in the document root and not allow it to see subdirectories? So what how do I get it to look in the sub-directory? Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601756 Share on other sites More sharing options...
DataRater Posted July 28, 2008 Author Share Posted July 28, 2008 I cannot read my banner http://space/spacebanner5.jpg I can definitely see into the subdirectory from the browser by doing http://space/pics/ it gives me the index which includes the spacebanner5.jpg file The ReWrite role is doing the correct things with $1 and $2 as I've investigated those. So why doesn't the following RewriteRule work??? RewriteRule ^(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601777 Share on other sites More sharing options...
corbin Posted July 29, 2008 Share Posted July 29, 2008 Oh dang.... I see the problem now. Let's take an example url http://blah.com/image1.jpg. That matches the regex so it'll be redirected to http://blah.com/pics/image1.jpg. The problem is here. http://blah.com/pics/image1.jpg also matches the regex, so it's redirected to http://blah.com/pics/image1.jpg. This repeats forever. Anyway, RewriteRule ^/(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] Will redirect stuff just in the root folder. For example http://blah.com/image1.jpg would redirect, but http://blah.com/sub_dir/image1.jpg would not. It seems the other regexps have the same problem, so you might want to add a / to the front of them. Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602315 Share on other sites More sharing options...
DataRater Posted July 29, 2008 Author Share Posted July 29, 2008 Hi Corbin, You're a genious!! It is doing a recursive rewrite ( I knew that) and your solution seems to have fixed it. (I didn't know your solution though). The ReWrite was doing http://space/spacebanner5.jpg http://space/bin/spacebanner5.jpg http://space/bin/bin/spacebanner5.jpg http://space/bin/bin/bin/spacebanner5.jpg ... Until Apache figured out it was in a loop. I'm trying to figure out why your solution works!!! duhhhh Thanks very much!!! Steve :-) Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602478 Share on other sites More sharing options...
DataRater Posted July 29, 2008 Author Share Posted July 29, 2008 Hi Corbin, I rebooted and it isn't doing exactly what I want. Let's recap. I want http://space/spacebanner5.jpg to go to http://space/bin/spacebanner5.jpg but it is re Your suggested rule RewriteRule ^/(.*)\.(ico|gif|jpg|png)$ /pics/$1\.$2 [NC,L] needs the \ removing from the end, like this RewriteRule ^/(.*)\.(ico|gif|jpg|png)$ /pics/$1.$2 [NC,L] and it won't map http://space/spacebanner5.jpg but it will map http://space/pics/spacebanner5.jpg Which not what i want. RewriteRule ^/(.*)\.(ico|gif|jpg|png)$ /pics/$1.$2 [NC,L] Seems to work ok but has the recursion problem so I'm going to try a ReWriteCond back later... Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602655 Share on other sites More sharing options...
corbin Posted July 29, 2008 Share Posted July 29, 2008 Oh, I see why the recursion problem is there. My regular expression experience has gone out the window apparently. . matches /, therefore, /pics/<blah> still matches. Blah! Try: RewriteRule ^/([^/]*)\.(ico|gif|jpg|png)$ /pics/$1.$2 [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602960 Share on other sites More sharing options...
DataRater Posted July 30, 2008 Author Share Posted July 30, 2008 Hi Corbin, I'm going to try your latest pattern some other time. I'm able to get on and will return to this issue later. Thanks for your help. You really have helped me. Thanks, Steve :-) Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-603452 Share on other sites More sharing options...
corbin Posted July 31, 2008 Share Posted July 31, 2008 No prob. Hopefully it works for real this time x.x. Quote Link to comment https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-604261 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.