Location header does not redirect to rewritten URLs

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
cleric
-


Joined: 15 Jun 2012
Posts: 2

PostPosted: Fri Jun 15, 2012 5:15 pm    Post subject: Location header does not redirect to rewritten URLs Reply with quote

Hello,

I have a problem which is easy to reproduce.

Let's say I have webroot with two files only.
r.php
test.php

I then add a URL rewrite as this:

Type: Global
RegEx: /rest(.*)
If this rule matches: Perform Internal redirect
Redirect to: /r.php$1
Non-mentioned options are with default values.

The contents of r.php is really not important. It could be an empty file. The whole point is that we can enter urls as this:
/rest/service/param
which will be rewritten to:
/r.php/service/param

Now if I write into the browser /rest/service/param everything works fine.
But let's say that test.php has this code:
Code:
<?php
header('Location: /rest/service/param');
?>


Then if I open /test.php in the browser I receive 404 error.

I've done many different test, also trying to use aliases instead of url rewrite (make alias /rest -> /r.php, and add /rest to be Script Paths) but the result is the same.

It all comes down to the fact that the web server performs the redirections based on the Location header, as Internal redirects. And moreover it seems that the server DOES NOT apply the rewrite rules to this process of internal redirection.
That's why when we say
Code:

header('Location: /rest/service/param');

The server detects the Location header supplied by php and starts the internal redirect BUT it tries to find a LITERAL directory structure and file as requested. I know this because if I create actual directories /rest/service with file 'param' inside, the redirection really servers that file. This proves that the URL rewriting is bypassed when Abyss makes internal redirection based the Location header. On the other hand, when URL rewriting is working we can never reach the 'param' file. You could never download 'param' by entering its url in the browser, but you can if a CGI script emits the location header.

So could you please suggest how this could be resolved. One way could be if Abyss could be told NOT to perform internal redirects but rather let the Location header down to the client browser and let the browser make the new request, which this time will be properly rewritten. But I haven't found such an option.

I tried searching the forum for similar problem but I couldn't find one. Please excuse me if this has been already answered.

Best Regards~
Back to top View user's profile Send private message
aprelium-support
-


Joined: 20 Feb 2009
Posts: 356

PostPosted: Thu Jun 28, 2012 2:22 pm    Post subject: Re: Location header does not redirect to rewritten URLs Reply with quote

cleric,

By default, URL rewiriting is not effective on internal paths and redirections. When you use the Location header as you did, you are asking for internal redirection.

So there are two solution:
* Enable the URL rewiriting rule for internal paths (check "Apply to subrequests too")
* Force the redirection to not be internal as follows:

Code:
<?php
header('Status: 302');
header('Location: /rest/service/param');
?>


As a general rule, it is recommended to enable URL rewriting debugging to understand what's going on and what is going under the hood when processing URLs and rewriting them.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group