Forum Moderators: phranque
Why doesn't something like this work?
RewriteRule ^clients/([AZaz09]+)$ ccc/clients/$1
I've put this in an .htaccess file in the root of my htdocs. Using Apache 2 if it matters.
Thanks for any help.
When I try testing, I get a 404 - not found as follows:
The requested URL /clients/example.php was not found on this server.
In my server error log, I find this error message:
[Thu Mar 17 21:55:09 2005] [error] [client 127.0.0.1] File does not exist: C:/Documents and Settings/Jeff/My Documents/My Webs/clients
[Note: My DocumentRoot is set to: C:/Documents and Settings/Jeff/My Documents/My Webs
The .htaccess file in which the RewriteRule lives is located in the same DocumentRoot location. ]
. . . graphics, stylesheets and other stuff on the page can't be found so the page displays very poorly. They are referred to in the html in the page using relative addressing (e.g. <link href="../styles.css" rel="stylesheet" type="text/css"> )
Is there a technique to rewrite these as well so the page works?
--ja
# exclude image and css files from rewrite
RewriteCond %{REQUEST_URI} !\.(jpe?g¦gif¦png¦css)$
... rule follows
[added] May I also suggest that you use the "relative-to-root" relative paths whenever possible? This makes it a lot easier to move things around and prevents many problems, while retaining the advantages of relative paths. (e.g. <link href="/common_stuff/styles.css" rel="stylesheet" type="text/css"> ) This path is always resolved relative to the Web root, so the browser always 'starts' looking in a known directory -- the top-level directory of your domain, as opposed to starting wherever it thinks the current location is. Doing this may resolve your problem without changing the mod_rewrite code. [/added]
Jim
I have a production server at domain.com with a hard-coded link in my nav bar to [domain.com...] The problem with that is that when I try to test the code on my local development box, clicking the login link takes me to the production server. So I made the link dynamic using php $_SERVER['HTTP_HOST'] -- that is, [<?php...] echo $_SERVER['HTTP_HOST'];?>/login.php.
The problem with that is that the documentroot of my development server contains the roots of several different sites. That is:
/htdocs
/htdocs/ccc
/htdocs/website1
/htdocs/website2
So, the ssl login page on my development machine is [localhost...] instead of the [domain.com...] on the production server.
I could change my php coding so that if $_SERVER['HTTP_HOST'] is 'localhost', it adds in the /ccc/, but then I have problems if I ever change the directory name or location on my development box. And I guess I'd still have the problems with other links on the page not being written root relative.
Should I be doing something other than rewrite? Setting up a vhost maybe? Any other thoughts?
Thanks for all your help!
--Jeff