Forum Moderators: phranque
RewriteRule ^(somedata)$ $1/ [R]
RewriteRule ^(somedata)/(.*)(\.[a-z]+)$ /mydata/$1 [L] I prefer to do it without redirectIf you want to keep the “real” filename and/or directory hidden, you have to do it without redirecting.
RewriteRule ^mydata/(.*)$ /somedata/$1 [NC,L]The second version will always be wrong, no matter what you're trying to do. With very, very rare exceptions, a (positive) REQUEST_URI condition belongs in the body of the rule, so the server doesn't have to evaluate conditions on every request ever. As it stands, all requests for anything in /somedata will be rewritten to /mydata/ and-that's-all--and you did say, didn't you, that /mydata/ contains lots of files and folders. Is it possible you've got mod_rewrite syntax mixed up with mod_alias syntax? In mod_rewrite you always have to capture; nothing gets reappended by default.
RewriteCond %{REQUEST_URI} ^/somedata
RewriteRule .* /mydata/ [NC,L]
From root I can see this:What does “see” mean? The problem is not with the pattern but with the target. When RewriteRules are used in any directory context--whether a <Directory> section of config or an htaccess file--the target is treated as a URI, meaning that the first / is the root of the current domain. But what does that mean if there are two domains involved: the one being requested, and the one whose directory the rule is located in?
^(.*)/somedata/(.*)$Never use .* or .+ at the beginning of a pattern if there is any conceivable way out of it. The server will capture all the way to the end of the string--and will then have to backtrack when it sees “Oh, oops, there has to be a /somedata/ after it”. (A server evaluating a Regular Expression basically operates in one dimension.) But the whole question is about to become moot, because ...
echoTralala, we can sidestep the whole problem. You don't need to say anything in htaccess at all; shift it to php. Within the php you can use either the DOCUMENT_ROOT approach--if you want things to be handled differently for each site--or the /full/literal/filepath/ approach--if you want all content served from the same place. Which one you use depends entirely on the requirements of the sites. To some extent you can combine the two, say if all sites use the same underlying code but then pull in site-specific data.
Or, when I use 'echo' in a php file it is correct that htaccess directives don't apply and this ...?htaccess doesn't touch php requests* ... but your htaccess may determine which exact php file is handling the request in the first place.
So what can I do to apply htaccess directives to the php files included this way in other php files?Whoa there. You’re mixing two different things. htaccess deals with external requests received by the server (and also with certain types of internal requests generated by some apache mods). php deals with, well, php. If /somefolder/ doesn’t physically exist, you can’t invoke it in php. You have to use its real, physical name.
The index.php page includes a number of scripts from 'myfolder',
which I try to retrieve with scripts like:
$path = $_SERVER['DOCUMENT_ROOT'];
include ($path . '/somefolder/header/index.php');
but in this case none of the external php files are retrieved correctly; the httaccess directive doesn't seem to work...