Apache question (technical)

jaguar • Nov 12, 2005 8:07 am
I'm playing around with Forcetype in an effort to clean up URLs, all well and good, I want it so that for example:
domain.com/type/item
gets echoed back to domain.com/index.php with the $vars type and item.

So far I've got a file called type that is a php file and is recognised as such, all well and good, all I need to do now is include index.php and we're cooking with gas.

This is where is gets odd. PHP thinks it's inside a dir called log, which of course doesn't actually exist and thus " require'index.php'; " craps out, as does " require'../index.php' ". There are plenty of tutorials out there on ForceType but none seem to deal with this issue of including files.

I've tried creating an absolute URL from $_SERVER['DOCUMENT_ROOT'] and adding the php but that was no good either.

Ideas?
Undertoad • Nov 12, 2005 10:31 am
Why does it think it's in log? Do you get an error message saying log/index.php doesn't exist?
jaguar • Nov 12, 2005 10:43 am
yup, to be exact:
Warning: main(index.php): failed to open stream: No such file or directory in /xxx/xxx/public_html/log on line 12
Fatal error: main(): Failed opening required 'index.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /xxx/xxx/public_html/log on line 12

Exactly why it thinks it's in a dir called log is beyond me.
Undertoad • Nov 12, 2005 10:48 am
Weird. Are you actually in public_html? Are there any .htaccess files changing things? Is there actually a directory public_html/log?
jaguar • Nov 12, 2005 12:00 pm
There's no DIR called log, just the php file with no extension which is in public_html. I've put the relevent bit .htaccess below, the rest is just auth.
[code]
(Files log)
ForceType application/x-httpd-php
(/Files)
[/code]
Brackets instead of angle brackets because the forum soft keeps taking them out, even when I put in code
Undertoad • Nov 12, 2005 12:58 pm
I don't think ForceType is what you want to use to do this. It seems ForceType is demanding a file named log, to be interpreted as a PHP file and living in /type.

I think you want to use URL rewriting. But URL rewriting is hard, and every time I look at the reference page I get a massive headache.
jaguar • Nov 12, 2005 3:20 pm
...and living in /type.

I don't understand that last bit.

URl rewriting is the other way of doing this but I get a headache too and every time I try it I just get Internal Server errors.
Undertoad • Nov 12, 2005 3:34 pm
Try this in the .htaccess of the base directory - this is just a guess, but:

RewriteEngine On
RewriteRule /(.+)\/(.+) ?type=$1&item=$2

Are there ANY directories in the root directory? You wouldn't be able to get to them...
jaguar • Nov 12, 2005 3:41 pm
need to access dirs, I'm going to take this golden opportunity to learn regular expressions and take occasional breaks with a punching bag.
Undertoad • Nov 12, 2005 3:46 pm
URL Rewrite will only be a decent solution if both "type" and "item" are uniform in some way - like, if they're both numbers, or a letter followed by a number, something you can identify that won't aloso identify the other directory names.

What I was trying to do was to capture the type (in-between slashes) and item, because in regular expressions, anything in parentheses gets "saved" as $1, $2 etc. Then once they are saved, use them to build a new URL address.

I should have used .* instead of .+

URL Rewrite is magical and scary. Regular expressions are sexy once you know them.
jaguar • Nov 12, 2005 3:47 pm
it's gonnabe something like..
RewriteRule ^log/([0-9]+)/$ index.php?page=log&id=$1

that one is giving me 404 errors but I can't be that far off.
Undertoad • Nov 12, 2005 3:49 pm
Nice. (Does the URL always have the preceding slash though?)
jaguar • Nov 12, 2005 3:50 pm
I'm adding a second line to deal with that when I get it working at all.
jaguar • Nov 12, 2005 3:59 pm
Well.
That works. Except for two odd problems, one the result of the other.

RewriteRule ^log/([0-9]+)/$ index.php?page=log&id=$1
Works fine but all links in index.php to stylesheets etc get broken.

RewriteRule ^log/([0-9]+)/$ index.php?page=log&id=$1 [R]
Works but puts the entire dir structure from server root in front of the domain:
http://www.xxx.xxx/xxx/xxx/public_html/index.php?page=log&id=1
Thoughts?
jaguar • Nov 12, 2005 4:09 pm
Interestingly I got PHP to echo its location back, it says exactly the same either way so I'm stumped.
jaguar • Nov 12, 2005 4:19 pm
A preceeding slash in all the URLs seems to have fixed that, mission accomplished. Thanks for the help UT, hope this thread is of use to some other poor soul one day.
Undertoad • Nov 12, 2005 4:22 pm
Wild-ass guess, maybe RewriteBase / before the second one?
Undertoad • Nov 12, 2005 4:23 pm
Never mind! Good going Jag!
jaguar • Nov 12, 2005 4:28 pm
Tried that, didn't seem to do much but left it in anyway, one of the superstitious things that'll probably cause me countless hours of frustration down the line when I forget, such is life =)
wolf • Nov 12, 2005 8:05 pm
jaguar wrote:
so I'm stumped.


me too.