Jump to content

Recommended Posts

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'?

 

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-600949
Share on other sites

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?

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601410
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601446
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601568
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601611
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-601777
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602315
Share on other sites

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 :-)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602478
Share on other sites

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...

 

Link to comment
https://forums.phpfreaks.com/topic/116865-apache-php-funneling/#findComment-602655
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.