Forum Moderators: phranque
I have a htaccess rule like:
RewriteRule ^(directory_1/.*)$ /bootstrap.php?url=$1/ [QSA,L]
I want any file in directory_1 (or it's subdirectories) to be redirected to bootstrap, with the requested URL passed in as a GET variable.
It currently works fine for well formed REQUEST_URI's, but if I miss a trailing slash off a directory, then the URL gets changed to
directory_1/directory_2/?url=directory_1/directory_2/ The page still loads, but I don't want that?URL to be added to the address.
Any ideas as to how to stop this from happening? I've spent a couple of days tinkering with this now and am getting quite frustrated.
Many thanks in advance.
Is this a commercially-hosted server, or did you configure it yourself?
Are the example URL-paths above completely accurate?
Does directory_1 ever contain the string "bootstrap.php"?
Where is bootstrap.php located in relation to directory_1?
Jim
Is this a commercially-hosted server, or did you configure it yourself? It is our own server. Running CentOS, and Apache 2.0.52
Are the example URL-paths above completely accurate? Does directory_1 ever contain the string "bootstrap.php"?
Where is bootstrap.php located in relation to directory_1? mod_dir appears to be working, as it adds the trailing slash before the?url=directory_1/directory_2, but I just have no clue as to why the url gets added... could it be a bug in the Apache version?
I think we're looking at a recursion problem here, where a redirect (from mod_dir, possibly) is 'exposing' your query string parameters. But since the ^directory_1 pattern does not match "bootstrap.php" URL-path, the scope of this problem must include other rules, directives, or possibly scripts beyond the code that you've posted.
In particular, if you have code intended to redirect browsers and search engine 'bots which request the dynamic URLs, then that code is likely involved in this problem.
One possible solution is to add mod_rewrite code to fix-up the missing slash "manually" without letting mod_dir do it. That has the advantage that you can explicitly control order of execution, because all directives within a given Apache module are executed in the specified order (this is not true if you mix directives from different modules; Those are executed on a per-module-ordered basis).
So, trying to get the complete requirements nailed down before we start coding, do you have any other 'agents' which may be redirecting, rewriting, aliasing, or 'meta-refreshing' URLs of the 'directory_1' or 'bootstrap.php' format?
Jim
Whilst trying some debugging this afternoon, I noticed a similar thread here relating where the solution was to use:
RewriteCond %{REQUEST_FILENAME}!-d
[Rewrite Code]
RewriteCond %{REQUEST_FILENAME} -d
[Rewrite Code]
[Final Rewrite Code]
Funny thing was that the -d never seemed to get triggered, even if we were requesting a directory.
I may have to give up on this and apply a workaround methinks. Thanks for your time.