![]() |
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? |
Why does it think it's in log? Do you get an error message saying log/index.php doesn't exist?
|
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. |
Weird. Are you actually in public_html? Are there any .htaccess files changing things? Is there actually a directory public_html/log?
|
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) |
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. |
Quote:
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. |
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... |
need to access dirs, I'm going to take this golden opportunity to learn regular expressions and take occasional breaks with a punching bag.
|
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. |
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. |
Nice. (Does the URL always have the preceding slash though?)
|
I'm adding a second line to deal with that when I get it working at all.
|
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? |
Interestingly I got PHP to echo its location back, it says exactly the same either way so I'm stumped.
|
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.
|
Wild-ass guess, maybe RewriteBase / before the second one?
|
Never mind! Good going Jag!
|
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 =)
|
Quote:
|
All times are GMT -5. The time now is 02:55 AM. |
Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.