Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to redirect all traffic to a single .php gateway file, this file will do authentication and use ajax to pull the file that was requested.

So I need a .htaccess with flow like this:

if external request for any file
redirect (or rewrite) to /gateway.php

gateway.php would then need to be able to access the file.

This is the best ive come up with is:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/gateway\.php$  
RewriteRule .* http://www.website.com/gateway.php?req=%{REQUEST_URI} [R=302,L]

This is working, but when the ajax on gateway.php tries to get the content from another page, it gets the content from gateway.php (because of the redirect). I need to add an exception somehow!

Any help would be greatly appreciated!

share|improve this question

migrated from stackoverflow.com Jan 26 '10 at 2:43

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 3 down vote accepted

You don't need that RewriteBase in there, try this:

RewriteEngine on
RewriteRule ^/gateway\.php$ - [L]
RewriteCond %{REMOTE_HOST} ^127\.0\.0\.1
RewriteRule ^(.*)$ - [L]
RewriteRule ^(.*)$ http://www.website.com/gateway.php?req=%{REQUEST_URI} [R=302,L]

First you explicitly say that if gateway.php is requested, stop. Then you say if it's from localhost just do the URL, ELSE do the redirect. You may be subject to some sort of internal redirect mechanism, you might have to set RewriteLog and RewriteLogLevel up right quick to debug the actions Apache is taking.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.