Forum Moderators: phranque
But I have a new problem. When redirecting, .htaccess does not allow the .php file to read sessions. The .php file works when called from a browser, but when called from .htaccess, the sessions are empty (I'm assuming because the server has no session).
What is a work around for this?
jdMorgan, the .php script is on the same domain as the .htaccess script. I've even tried handling it with another cookie specifically set for this purpose, but no luck there, either.
Still trying to figure this out. The completion of my project hinges on this one problem.
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^system/getimage\.php$
RewriteRule (.*) http://www.example.com/system/getimage.php?i=$1 [R=301,L]
A server headers checker such as the "Live HTTP Headers" add-on for Firefox/Mozilla browsers would show a loop clearly as a series of redirects, ending with "GET /system/getimage.php?i=system/getimage.php HTTP/1.1"
Jim
The session value holds the data "example.com" and should be inserted by the php file to http://www.example.com/media/image.jpg.
Would anyone mind to bother with testing this on their server?
First, the php file does not "go client side." If it's working properly, the php code is parsed by the php interpreter on your server, and the HTML output of the PHP is sent to the client.
Second, the php is not "called from .htaccess." The .htaccess code merely sends a 301 redirect response to the client, which then issues a new request using the new URL sent in that redirect response -- The URL you specified in your RewriteRule.
If the 'realm' of the cookie is set correctly. then it will be sent with *all* requests from the client to any URLs within that realm on your domain. The only conditions under which the cookie will not be sent are if it expires or if the cookie's realm does not match the requested URL-path.
The intent here is not to be picky, but rather to prevent confusion and possibly to save you some time.
Jim
My .htaccess file is located:
http://www.example.com/content/media
My .php script is located:
http://www.example.com/scripts/
That should be within the same 'realm', shouldn't it?
You can control these from php, see session.cookie_path, session.cookie_domain and session.cookie_domain in the documentation of Sessions [php.net] within the PHP documentation.
You can control these from php, see session.cookie_path, session.cookie_domain and session.cookie_domain in the documentation of Sessions [php.net] within the PHP documentation.