Forum Moderators: phranque
I am developing on my local machine and am using the Layer pattern to code. All the GUI code is in the GUI directory, but I don't want the users to be aware that they are actually looking at files in the GUI directory.
I thought that this would work, but it doesn't:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost/office/GUI$ [NC]
RewriteRule ^(.*)$ [localhost...] [L]
The above is in the .htaccess file, and mod rewrite is working.
Any help would be greatly appreciated.
HTTP_HOST contains only the hostname, optionally followed by a port number, and RewriteRules "see" only the local URL-path. You'll also need a RewriteCond to prevent an 'infinite' rewriting loop. One way to do it:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost
RewriteCond $1 !^GUI/
RewriteRule ^office/(.*)$ /office/GUI/$1 [L]
If your users are already aware of the /GUI subdirectory, and you are trying to 'correct' that situation, then you need the opposite function as well -- externally redirecting /office/GUI/<anything> to http://localhost/office/<anything>
That's a bit trickier, but if you need to add that function after getting the above code working, just let us know.
Jim
Thank you for your advise. Maybe I am think of this in the wrong way.
My directory structure is as follows:
BL(dir)
DL(dir)
GUI(dir)
There is nothing in the root directory (C:\xampp\htdocs\office) besides the directories above.
I would like to set up apache to point to C:\xampp\htdocs\office but every request made to [localhost...] should get it's data from [localhost...] without actually showing the user that the GUI exists.
Do you think this is possible?
Thanks again for your help
...every request made to [localhost...] should get it's data from [localhost...] without actually showing the user that the GUI exists.Do you think this is possible?
Yes, it is not only possible, but easy. Please test the code posted above by placing it in
C:\xampp\htdocs\.htaccess
Then let us know if you have any further trouble.
Jim
Ok, I've made a .htaccess, with the the exact code you have given me, still no luck I'm afraid.
I put the file in C:\xampp\htdocs and nothing changed, so I put the file into C:\xampp\htdocs\office with still no change.
If it was working and I put it into C:\xampp\htdocs would that not affect all websites running in that directory? Or when it goes live, it will have it's own directory with the same structure.
Sorry to be a pain.
Here is the last bit in the error log, nothing out of the ordinary there:
[Wed Jun 13 14:55:49 2007] [notice] Server built: Mar 5 2007 11:23:00
[Wed Jun 13 14:55:49 2007] [notice] Parent: Created child process 4940
[Wed Jun 13 14:55:50 2007] [notice] Child 4940: Child process is running
[Wed Jun 13 14:55:50 2007] [notice] Child 4940: Acquired the start mutex.
[Wed Jun 13 14:55:50 2007] [notice] Child 4940: Starting 250 worker threads.
[Wed Jun 13 14:55:50 2007] [notice] Child 4940: Starting thread to listen on port 80.
[Wed Jun 13 14:55:50 2007] [notice] Child 4940: Starting thread to listen on port 443.
And this is the last bit of the Access log:
127.0.0.1 - - [13/Jun/2007:15:00:04 +0100] "GET / HTTP/1.1" 200 1991
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/ HTTP/1.1" 200 20853
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/office.css HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/okgo.png HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/office.png HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/briefBottomCorner.gif HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/briefBottomRight.gif HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/liLink.png HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/briefSideBg.gif HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/briefBottomBg.gif HTTP/1.1" 304 -
127.0.0.1 - - [13/Jun/2007:15:00:06 +0100] "GET /office/GUI/images/demouk.png HTTP/1.1" 304
If you wish to move the code to /office/.htaccess, then it must be changed to reflect that:
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^localhost
RewriteCond $1 !^GUI/
RewriteRule ^(.*)$ /office/GUI/$1 [L]
Options +FollowSymLinks
Your test case was incorrect. Your access log shows requests for /office/GUI/somefile, which is the actual location of the files, and your server is returning 304-Not Modified, indicating that your browser has previously cached those resources, they have not been modified since that time, and that the browser may therefore serve the resources from its local cache. You should be requesting the URL /office/somefile, which the code will then silently 'map' to the filepath /office/GUI/somefile
Note the distinction: URL versus filepath.
If you wish to prevent direct access of the files in /office/GUI/, then that is step two, as noted in my first response. You need to get step one working first, to avoid needless complication.
Also, as implied by the discussion of the 304 response above, you should flush your browser cache after making any change to your server configuration files, such as .htaccess.
Jim