Forum Moderators: phranque
I was looking thru the forum for something similar but I didn't see anything and apache is not my best skill :-(
Here is the case:
1. Ussing Apache for windows in my own pc, for local development.
2. .htaccess
============
RewriteEngine on
RewriteRule ^(.*).html /gp4v2/index.php?html_page=$1 [L]
3. php script (this is not the issue)
=====================================
<?
$html_page = (isset($_GET['html_page']))? $_GET['html_page'] : "index";
echo "html_page=$html_page";
switch ($html_page) {
case "index":$html_tpl = "tpl/index.tpl";
break;
default:$html_tpl = "tpl/index.tpl";
}
$html_code = file_get_contents($html_tpl);
echo $html_code;
?>
What I'm trying to do is the redirect every request for an .html page to a single .php script that will create the html code according to the url parsing.
In this example:
1. If I type [localhost...]
It works fine, by default I'm loading a file tpl/index.tpl and the .css file is being parsed.
2. If I type [localhost...]
It also works fine, again defaul file is showed and the .css files gets parsed.
3. But when I type [localhost...]
It partially works.. the php script is being executed (I know that because I'm displaying the value I got in the URL parameter), I can see the html code, but the .css is not parsed and in addition I can see an error in the apache error.log file, this is the error:
[Fri Apr 09 15:42:17 2004] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Group/Apache2/htdocs/gp4v2/xys, referer: [localhost...]
Looks like apache is looking for the non existent folder "xys", because it is in the URL, I'd like to avoid this because I'm ready to parse the whole string in the URL so the '/' won't be an issue for me in the script, but looks like apache is stoping before to look for the .css file.
Any idea what is wrong here?
Thanks a lot for your support.
Carlos.
Checking into the access.log from the apache I found this:
127.0.0.1 - - [09/Apr/2004:16:11:53 -0400] "GET /gp4v2/xys/style.css HTTP/1.1" 404 293
Which confirms that it is looking for the .css file in a folder that does not exist, intead of look for it in the root folder.
But.. still trying to sort it out :-(
Anyone?
Thaks again.
This all really depends on how much of the requested URL-path you want to pass to the script in the query string. The way you have written it, the entire path is passed, including subdirectory names.
With a minor correction this is what you are using now:
RewriteEngine on
RewriteRule ^(.*)\.html$ /gp4v2/index.php?html_page=$1 [L]
RewriteEngine on
RewriteRule ([^/.]+)\.html$ /gp4v2/index.php?html_page=$1 [L]
So, with your code, requesting [localhost...] will result in a query string value of "?html_page=xyz/xyzw", while with the modified code, the query string will be "?html_page=xyzw".
Jim
That's correct, you examples are what I can see and is fine becasue each word in between the '/' will be a parameter for me, and I'm using a parser function to separate them. I can have multiple parameters acording to the structure of my page then the way is working is perfect.
The question is: why the root folder is being moved? I'mean, if I have a page like [localhost...] I'll get abc/xyz in the parameter, that is fine, but then every reference from my html code, 'like href=style.css' will start under 'abc' (looking the file like 'abc/style.css'), directory which does not exist, I have to use explicit reference like 'href=/gp4v2/style.css'.
I don't know if you get my point... do you?
Thanks
CS.
You may want to try removing the leading slash from the RewriteRule substitution - I believe I've seen that fix posted here before in a previous thread (but I can't find it). :(
Jim
That means that it is an issue that needs to be workerd out as you are pointing .. it is what I'm doing now. So basically is nothing wrong with my mod_rewrite rules nor my appache config which is what I was thinking.
The only think I don't like of this is that while I'm working on my own pc I have an extra folder which is the root for my website (like ... c:\Prog....\htdocs\mywebsite\..) so I need to use the references like '/mywebsite/style.css' and once I deploy to my hosting server \mywebsite\ exists over there, but it is the root for the addon domain wwWebmasterWorldebsite.com, then I have to take out the '/mywbesite' and use the references like '/style.css' only .. but I think I'll be able to handle that using some extra php code.
or is there some way I can configure a 'site' in the apache for my own pc indicating the root folder is (c:\prog....\htdocs\mywebsite\), so when I use a reference like '/style.css' it will go back to that folder and not to the \htdocs\ default folder? I'll try to read about that a little more, that way I can avoid the extra php code which could be a little overload.
Thanks again for all your support.
Carlos.
But what if I have more that one folder, each one with a different website?
like [localhost...] [localhost...] and I use a .htaccess for each folder?
When I publish that in my hosting /site1/ is going to www.site1.com and /site2/ is going to www.site2.com, then the 'root' for each one will be '/' so for the case of the .css file which is in the root I'll use for both the reference like '/style.css', while when I'm on my own PC I need to use '/site1/style.css' and '/site2/style.css' .. this is just the case with one reference, but when you have many to edit the references is a pain :-(.
I have been playing with the <VirtualHost> and the Alias on my PC trying to get the same behavior but no luck so far :-(
Thanks,
Carlos.