Forum Moderators: phranque

Message Too Old, No Replies

Simple redirect, where am I going wrong?

No input file specified

         

csdude55

8:47 pm on Dec 20, 2022 (gmt 0)

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



I wanted to set it up so that if a user goes to example.com/personals/foo or example.com/friendfinder/foo, they'll see the results for example.com/personals/view.php?perma=foo.

I have several CONF files and haven't seen any other errors. This is the contents of the CONF file specific for this section, though:

RewriteEngine on

RewriteRule ^/friendfinder /personals [NC,L]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteRule ^/personals/([^/]+) /personals/view.php?perma=$1 [QSA,NE,NC,L]

# I originally had this instead of the above, but I'm not sure that I have to specify both since I redirect earlier anyway
#RewriteRule ^/(?:friendfinder|personals)/([^/]+) /personals/view.php?perma=$1 [QSA,NE,NC,L]

But view.php only displays "No input file specified."

/var/log/apache2/error_log only has this:

[Tue Dec 20 15:34:43.027165 2022] [proxy_fcgi:error] [pid 9622:tid 47549292066560] [client 123.45.67.89:28440] AH01071: Got error 'Unable to open primary script: /home/example/www.example.com/personals/view.php (No such file or directory)'

If I go to example.com/personals/view.php then I get the expected result, so it DOES exist.

I stripped the PHP script down to the bare basics to rule out a PHP problem, and I still get the same error:

<?php
echo "Done";
?>

The code seems OK with this tester (removing the opening / since it tests .htaccess instead of .conf):

[htaccess.madewithlove.com?share=03bf4a08-087a-4e37-9a1b-100664b3fe45...]

I also tried changing [L] to [PT], and tried adding R=301 to see if I can narrow down what's happening. But I still get the same error.

If the problem isn't with this specific CONF script then I have to assume there's a conflict somewhere else. But with literally thousands of lines, I have no idea where to even start! I searched for any reference to "personals" and didn't find anything that looks like a conflict, but for all I know there could be a .+ or something that's matching when I didn't expect it :-/

Before I spend the rest of the year looking through thousands of lines of code, do you see anything here that might be causing the problem?

Or any other suggestions on this "No input file specified" error in general?

csdude55

9:41 pm on Dec 20, 2022 (gmt 0)

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



FYI, all of the info I'm finding on Google about this refer to it being a FastCGI error, and that a modification has to be made:

[hiren.dev...]

But I have another CONF that's similar, and it works fine:

RewriteEngine on
RewriteRule ^/classifieds/[\w-]+?/(\d+)/?$ /classifieds/view/index.php?id=$1 [QSA,PT]

So it's not an issue with FastCGI, it has to be either my code or a conflict somewhere.

Assuming that the CONF files are ran in numeric order, the one here (for classifieds) is 40.conf. The next one is 50.conf, and it's small enough that I can see no conflicts. And then the one I'm having an issue with is 60.conf. Theoretically, if there was an issue before 40.conf then it would have caused the same error, so it HAS to be with the 60.conf code! But I just don't see the problem :-/

csdude55

6:33 am on Dec 21, 2022 (gmt 0)

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



I guess this is an update?

So I went through the CONF and removed everything but the very bare essentials:

RewriteEngine on
RewriteRule ^/personals/([^/]+) /personals/view.php?perma=$1 [R=301]

Restarted Apache, and that worked.

So I started adding things back in, one line (or letter) at a time. Add something, restart, test. Add something else, restart, test.

And after it was all done, I have everything add back in exactly like it was. And it's still working!

Now that's frustrating. I have no idea why it wasn't working, and no idea why it's working now. Maybe restarting Apache 75 times fixed it? Who knows. But I'm pretty sure that it'll stop working in a few days and I'll find out that what appears to be working now is really just from cache or something.

Sgt_Kickaxe

6:45 am on Dec 21, 2022 (gmt 0)



I wanted to set it up so that if a user goes to example.com/personals/foo or example.com/friendfinder/foo, they'll see the results for example.com/personals/view.php?perma=foo.

I don't think this is a technical issue, just a misunderstanding between redirect and rewrite?

A redirect is taking a visitor FROM example.com/foo TO example.com/personals. A rewrite is taking the content FROM example.com/personals and showing it ON example.com/foo. Do you want the content from one file to show on a different URL or do you want the visitor to go from one URL to another?

If it's a rewrite you want, ie: take the content from a php file and show it on a different URL...
RewriteRule ^personals/foo$ /personals/view.php [L]

Whatever is in view.php will be shown at example.com/personals/foo . Make sure you get the path right for the view.php file. If it's in a cache folder you would need to change the rewrite to /personals/cache/view.php.... or wherever it is, but the URL to show it on would not change.

Note: If you have php code in the file some hosts require that you use a php ending to the file. If you use .html or no ending at all the php code may just be posted and won't execute.

csdude55

6:19 pm on Dec 21, 2022 (gmt 0)

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



I think I just used the wrong word, but understand the concept. My goal here is a rewrite: if a user goes to example.com/personals/foo or example.com/friendfinder/foo, they'll see the results for example.com/personals/view.php?perma=foo without being physically redirected.

I added the [R=301] for testing, so that I could see what was happening behind the scenes. But I was still getting the same error.

Awhile back I was having an issue with Perl scripts where I would upload a perfectly fine script and get an error, but then I could delete it and re-upload the same script and it would work. I think it was a hiccup with my home internet service? Either way, I'm guessing that the last time I uploaded this CONF file I had a similar hiccup, so where I was uploading modifications and overwriting it (instead of deleting it first) I was getting that same problem. It's only when I deleted it and re-uploaded that it worked.

But that's seriously just a guess.

lucy24

6:26 pm on Dec 21, 2022 (gmt 0)

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



Edit: We overlapped, but I think I got it right ;)
just a misunderstanding between redirect and rewrite?
That was my first thought too. But I think what csdude was doing was testing the RewriteRule by first making it an external redirect, to make it easier to see what's happening--it's right there in the browser's address bar, not hidden in server logs--and then changing it back to the internal rewrite shown in the original post.

In this specific situation, though, it might be better to use R=302 (or simply R) so the browsers you're testing it on don't remember the redirect when you don't want them to.

phranque

12:40 am on Dec 22, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



if a user goes to example.com/personals/foo or example.com/friendfinder/foo, they'll see the results for example.com/personals/view.php?perma=foo

not related to your error message, but this is the definition of a canonicalization problem.
you should redirect the noncanonical url request to the canonical url and then rewrite requests for that url.

If I go to example.com/personals/view.php then I get the expected result, so it DOES exist.

i would try removing the view.php file and retrying this url to see if you get the same error message as the rewrite of the example.com/personals/foo url.

I also tried changing [L] to [PT], and tried adding R=301 to see if I can narrow down what's happening. But I still get the same error.

this seems to contradict the statement quoted above...

what happens when you directly request the following url?
example.com/personals/view.php?perma=foo