This is a discussion on mod_rewrite: [internal redirect] returns 301 within the Linux Web Servers forums, part of the Web Server and Related Forums category; Hi, I'm using Apache 2.0.47 / FreeBSD with a RewriteRule which redirects every request for a non-regular ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm using Apache 2.0.47 / FreeBSD with a RewriteRule which redirects every request for a non-regular file to a script: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /a/prc?c=$1&%{QUERY_STRING} This works great, but if the directory, the RewriteRule is applied to contains a subdirectory that has the same name as the requested resource, things become strange! I've got no Idea how to explain the servers behavior, so I'll give an example: /a/ is the DocumentRoot /a/prc is the processing script /a/usage this file does not exist /a/usage/ this directory exists Now the following request is performed: GET /usage HTTP/1.1 [...] In the RewriteLog (Level 9) everything still looks fine and the server came to the decision, a internal redirect is appropriate: (3) [per-dir /a/] strip per-dir prefix: /a/usage -> usage (3) [per-dir /a/] applying pattern '^(.*)$' to uri 'usage' (4) RewriteCond: input='/a/usage' pattern='!-f' => matched (2) [per-dir /a/] rewrite usage -> /a/prc?c=usage& (3) split uri=/a/prc?c=usage& -> uri=/a/prc, args=c=usage (2) [per-dir /a/] strip document_root prefix: /a/prc -> /prc (1) [per-dir /a/] internal redirect with /prc [INTERNAL REDIRECT] but to the client '301 Moved Permanently' is returned: HTTP/1.1 301 Moved Permanently Location: http://[...]/usage/?c=usage I got absolutely no idea whats wrong. I don't think, the RewriteRule ist the problem, because in the RewriteLog everything is exactly as is should be. I suppose there is another module which causes things to get messed up. I really appreciate your suggestions. TIA && Regards Thorsten |
|
|||
|
> but to the client '301 Moved Permanently' is returned:
> > HTTP/1.1 301 Moved Permanently > Location: http://[...]/usage/?c=usage > > I got absolutely no idea whats wrong. I don't think, the RewriteRule ist > the problem, because in the RewriteLog everything is exactly as is should > be. I suppose there is another module which causes things to get messed up. i think you're right in saying that mod_rewrite is not to blame here. the behaviour to send a redirect in the case of a user requesting a directory without the trailing slash is perfectly normal: GET /usage HTTP/1.0 HTTP/1.1 301 Moved Permanently Location: http://[..]/usage/ is the normal behaviour - so this looks like apache has already decided it needs to send a redirect with a trailing slash, but is first having a quick look at the per-directory rewrite rules (which are evaluated very late) and then gets confused (rewrite-engine ends in internal redirect to /a/prc and has set query string but the info that we need to have an external redirect to the dirname plus trailing slash is still there and takes place. things to try: - use [R] to force an external redirect to /a/prc yourself - move this rule into the httpd.conf - per-directory rules eat a lot performance and have some hidden caveats which often come from the fact that they're evaluated a lot later than regular rewrite rules in httpd.conf. joachim |
|
|||
|
Joachim Ring wrote:
> is the normal behaviour - so this looks like apache has already > decided it needs to send a redirect with a trailing slash, but is > first having a quick look at the per-directory rewrite rules (which > are evaluated very late) and then gets confused (rewrite-engine ends > in internal redirect to /a/prc and has set query string but the info > that we need to have an external redirect to the dirname plus > trailing slash is still there and takes place. > [...] > - move this rule into the httpd.conf - per-directory rules eat a lot > performance and have some hidden caveats which often come from the > fact that they're evaluated a lot later than regular rewrite rules in > httpd.conf. Hello Joachim, thank you very much for your fast reply. I moved the entire stuff into httpd.conf and it works fine. Another good example how small things could make you waste a huge bunch of time: I was going to move the rules into httpd.conf lateron anyway! Thorsten |
| Thread Tools | |
| Display Modes | |
|
|