The Cellar

The Cellar (http://cellar.org/index.php)
-   The Internet (http://cellar.org/forumdisplay.php?f=8)
-   -   Apache question (technical) (http://cellar.org/showthread.php?t=9548)

jaguar 11-12-2005 07:07 AM

Apache question (technical)
 
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 11-12-2005 09:31 AM

Why does it think it's in log? Do you get an error message saying log/index.php doesn't exist?

jaguar 11-12-2005 09: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 11-12-2005 09: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 11-12-2005 11:00 AM

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)

Brackets instead of angle brackets because the forum soft keeps taking them out, even when I put in code

Undertoad 11-12-2005 11:58 AM

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 11-12-2005 02:20 PM

Quote:

...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 11-12-2005 02: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 11-12-2005 02: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 11-12-2005 02: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 11-12-2005 02: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 11-12-2005 02:49 PM

Nice. (Does the URL always have the preceding slash though?)

jaguar 11-12-2005 02:50 PM

I'm adding a second line to deal with that when I get it working at all.

jaguar 11-12-2005 02: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_ht...?page=log&id=1
Thoughts?

jaguar 11-12-2005 03:09 PM

Interestingly I got PHP to echo its location back, it says exactly the same either way so I'm stumped.


All times are GMT -5. The time now is 06:49 PM.

Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.