Forum Moderators: phranque

Message Too Old, No Replies

No input file specified, where did I go wrong?

         

csdude55

12:20 am on Mar 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I haven't worked on this in months, and now I honestly can't even remember what I was doing! LOL I'm hitting a road block, though, so I'm hoping fresh eyes can see where I messed up.

I have this URL working fine:

https://www.example.com/forum

I'm trying to set it so that if the user goes to:

https://www.example.com/forum/foo/

then the server will display:

https://www.example.com/forum?topic=foo

Right now, if I manually go to example.com/forum?topic=foo then the page works fine, but when I go to example.com/forum/foo then I'm getting "No input file specified." So I know that the issue is definitely with the configuration.

This is the whole thing in Apache conf:

RewriteEngine on

RewriteRule ^/forum/(foo|bar)(?:/(.+))? /forum/$2?topic=$1 [NC,QSA]

# I also have these rules...
#
# to change example.com/forum/this-is-a-subject/12345 to example.com/forum/view.php?id=12345
RewriteRule ^/forum/[a-z-]+/(\d+)/?$ /forum/view/index.php?id=$1 [NC,QSA,L]

# to change example.com/forum/favorites to example.com/forum/index.php?favorites=1 or
# example.com/forum/foo/favorites to example.com/forum/index.php?topic=foo&favorites=1
RewriteRule ^/forum/(favorites|post)(?:\.php|/)?$ /forum/index.php?$1=1 [NC,QSA,L]

# if there's no ID# then search by the this-is-a-subject part of the URL
RewriteRule ^/forum/([a-z-]+)/?$ /forum/index.php?p=$1 [NC,QSA,L]

# safety net
RewriteCond %{QUERY_STRING} (?:^|&)topic=[a-z-]+ [NC]
RewriteRule ^/forum(?:/(.+))? - [NC,L]


Do you see where I messed up? I'm assuming that I intentionally left off [L] from the first rule so that the "favorites" section would work, but it's been awhile since I wrote it :-O

phranque

12:42 am on Mar 17, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what happens when you manually request manually request this?
example.com/forum/?topic=foo

btw all those requests for urls containing query strings should probably be externally redirected to the canonical urls.

phranque

12:57 am on Mar 17, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



also, did you check the web server error log file?

csdude55

3:55 am on Mar 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what happens when you manually request manually request this?
example.com/forum/?topic=foo

The PHP page works exactly as expected, so I'm sure that the issue is with the configuration.

also, did you check the web server error log file?

I looked at /var/log/apache2/error_log, but nothing was helpful; just a ton of expected mod_pagespeed warnings. I modified PHP to write errors to MySQL to eliminate duplicates, and it had a few PHP warnings but that's all... again, nothing helpful :-(

csdude55

4:56 am on Mar 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think I figured out the problem. Since I wasn't 301 rewriting, the 4th rule was catching it and rewriting it again:

RewriteRule ^/forum/([a-z-]+)/?$ /forum/index.php?p=$1 [NC,QSA,L]

The "fix" was to add [PT] to the first rule, then change the [L] to [PT] on the other rules. Luckily I vaguely remembered something about that from before, and was able to scroll through my old threads to find the suggestion.

I really don't understand the logic behind [PT], but I mess with the configuration so rarely that I guess I don't really HAVE to understand...

lucy24

4:15 pm on Mar 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I really don't understand the logic behind [PT]
It's one of those flags that you never have to think about until you move from htaccess to your own server, because it’s implied in directory contexts. It mainly comes into play when the result of a RewriteRule has to interact with a later mod_alias rule.

That's assuming the rule is lying loose in config (in this context, inside a <VirtualHost> envelope counts as “lying loose”). If it’s actually in a <Directory> section, the flag ought to make no difference, so that’s a head-scratcher.

Docs also confirm that [PT] implies [L]. So retaining [L] instead of replacing it is redundant but has no other effect. Er, should have no other effect.

csdude55

5:23 pm on Mar 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In this case I've moved all of my configuration files to /etc/apache2/conf.d/userdata/ssl/2_4/. It's a bit of a pain to set up because I have to rebuild and restart after every minor change, but in theory it will process faster so... short term pain for long term gain, I guess.

I originally added [L] to that first line and it fixed the immediate problem, but then when the user had an URL like:

example.com/forum/foo/whatever/12345/

it was being rewritten to:

example.com/forum/whatever/12345/?topic=foo

instead of the expected:

example.com/forum/view/index.php?topic=foo&id=12345

That's when I remembered our conversation before, and I went through our old conversations and found the [PT] suggestion. That appears to have fixed all of it.

That's what I don't quite get... if [PT] tells it to "pass through" then it seems to be the same as no flag at all! It would move on to the second rule either way. But if it's redundant with [L], then it shouldn't have allowed the second rule to run.

Unless it's more like, "stop here, but rerun all rules from the top and remember this new path without redirecting"?

lucy24

5:02 am on Mar 18, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[PT] means “treat the target of a Rewrite as an URL rather than as a filepath”. That's why it has to be implied in htaccess; the site owner may not even know the physical filepath. (I worked mine out by looking at error logs, which give filepath rather than URL.)

in <Directory> or htaccess
RewriteRule blahblah /some/stuff/here [L]
really takes you to--for example--
/users/yourname/example.com/some/stuff/here [L]

while in the config file the same rule would take you to, literally,
/some/stuff/here
which probably doesn't even exist.

So you have to either use the [PT] flag or change all your targets to give the physical filepath.

:: detour to check something in docs ::

Well, phooey. You can't set a RewriteBase except in a directory/htaccess context, and it refers to an URLpath, not a physical filepath. Don't think I ever appreciated that detail.

csdude55

5:21 am on Mar 18, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hmm. OK, that's interesting and very helpful! Thanks, Lucy :-D