views:

619

answers:

2

I just want to catch all requests and forward them internally to my catchall page with all POST data intact

Catch all page: http://www.mydomain.com/addons/redirect/catch-all.php

I've tried so many combinations, but my server doesn't want to redirect internally if I specify more than catch-all.php

# Internally redirect all pages to "Catch" page
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) /addons/redirect/catch-all.php [L]

Also, do I need [L] or is it useless for internal redirects?

Then, what php code would I use to grab the POST data, use it, and finally PHP redirect the page to the originally requested page

Would it be done just as normal by using $_POST['variable_name']; or something different? Then, how would I go about calling the originally requested page, so I can tell PHP to header location direct them to that page?

Thanks!

UPDATE:

Ha sick, nevermind. The condition DOES work. Here's my code:

# Internally redirect all pages to "Catch" page
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/robots.txt$ 
RewriteCond %{REQUEST_URI} !\.(gif¦jpe?g¦png¦css¦js¦pdf¦doc¦xml)$

RewriteCond %{REQUEST_URI} !^/addons/redirect/catch-all\.php$
RewriteRule (.*)$ /addons/redirect/catch-all.php?q=$1 [L]

Thanks guys for the inspiration! Now time to get that PHP to work...

A: 

I think what you have will redirect requests for images and .js files as well. Also, any PHP header() redirect would just smack right into the RewriteRule again, wouldn't it? If you want some code to process on each page before running the requested page, and the requested pages actually exist, why not just have a header file that's included in all your pages? Then the header file could include the catch-all code you want to run (or an include() for it). No RewriteRule required.

hlpiii
A: 

L is for last, or stop here. It's fine.

# Internally redirect all pages to "Catch" page
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) /addons/redirect/catch-all.php?q=$1 [L]

This will store the original location as $_GET['q']

Process your $_POST stuff normally, being careful not to output anything, then:

header('Location: ' . $_GET['q'],true,302);

302 means temporary redirect.

Not tested, but I do something similar to redirect logins.

EDIT: Hmm.. That will cause a loop as is. You will need some other RewriteRule to know when you've already redirected a user. Perhaps append ?q=redirected on the original url and use that as a stop for another RewriteRule?

I suppose you could also use a symlink to your web root to tell the difference.

/var/www/html/blah linked back to /var/www/html

then after catching the post you send all users to /blah instead. Same content, two paths, one accessible directly, one only through your catch all.

Daren Schwenke
I'm really new to this - if you can give an example of how to do the first thing I'd appreciate that.I thought that I could do a condition like this - but it doesn't seem to work:RewriteCond %{REQUEST_URI} ^/addons/redirect/catch-all.php$ RewriteRule (.*) /addons/redirect/catch-all.php?q=$1 [L]Basically, redirect all directors to "catchall" but if its "catchall" then don't redirect - how come this doesn't work>
RB