homepage Welcome to WebmasterWorld Guest from 54.205.247.203
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Clean URLs now fail on new server
I'm moving from PHP Apache to PHP CGI-BIN
DerekH




msg:3968833
 4:44 pm on Aug 9, 2009 (gmt 0)

I've just moved my website from a server with PHP running in Apache, to a server where PHP runs as CGI in my CGI-BIN.

I'm not overly familiar with .htaccess files, but two years ago, someone kindly gave me some rewrites so that I could have clean URLs when I moved my site from HTML to PHP, using the rewrite code here...

# Externally redirect direct client requests for "index.html" or "index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html¦php)
RewriteRule ^index\.(html¦php)$ mywebsitenamehere/ [R=301,L]

# Internally rewrite requests for "index.html" or "/" to "index.php"
RewriteRule ^(index\.html)?$ /index.php [L]

# Externally redirect direct client requests for "anything-else/index.html" and "anything-else/index.php" to "/"
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.*)/index\.(html¦php)
#RewriteRule ^(.*)/index\.(html¦php)$ $1/ [R=301,L]

That all worked beautifully.
My PHP isn't a database app with arguments passed on the URL, it's just an HTML site where I use one or two facilities of PHP to do one or two tasks for me, so I've several hundred different filenames that I'd like to have clean URLs

Now I've moved the website to the new server, it would appear that by the time the htaccess is run, the PHP file
"mydomain/myfolder/index.php"
has been re-written into
/cgi-bin/php5.cgi/myfolder/index.php
and now the re-writes whip the index.php off the end of that, and all hell breaks loose.
I can't even get the first rewrite to work - I can't whip the index.php off my home page, though if I type in my homepage without an index file (just the domain name) it all works.

Despite considerable googling, I can't find what I should be doing to get clean URLs in this case.

Anyone here have a solution that's easy to understand?
I don't have long before my domain name points to the new server, rather than the old one where the site still exists and works....
I'm on a shared host, so I don't have access to httpd.conf etc...
DerekH

 

Caterham




msg:3968846
 5:49 pm on Aug 9, 2009 (gmt 0)

/cgi-bin/php5.cgi/myfolder/index.php
and now the re-writes whip the index.php off the end of that, and all hell breaks loose.

Either exclude the path via a rule above all or switch the whole thing off by placing a .htaccess into your cgi-bin with
RewriteEngine off. That would prevent runtime execution of mod_rewrite as well (excluding won't).

BTW;
# Internally rewrite requests for "index.html" or "/" to "index.php"
Since you're redirecting index.html requests... instead of rewriting internal lookups for index.html like those caused by mod_dir (DirectoryIndex) you may want to adjust DirectoryIndex to DirectoryIndex index.php

DerekH




msg:3968851
 6:07 pm on Aug 9, 2009 (gmt 0)

That's very elegant, Caterham, and almost works :-)

It certainly stops the /cgi-bin/php5.cgi/myfolder problem, but I'm finding the rewrites aren't rewriting the PHP files, only the HTML files.

It seems to be that by the time the htaccess (which is in the top level director) first gets hold of the request, it's *already* been rewritten from
myfolder/index.php to
cgi-bin/php5.cgi/myfolder/index.php

That's the bit I don't understand or see how to cure.
Does that make more sense?
DerekH

Caterham




msg:3968861
 6:47 pm on Aug 9, 2009 (gmt 0)

Interesting setup. So a <Directory /path/to/myfolder> (or a .htaccess file there) with potential password protection etc would be bypassed.

There are definitely not two rounds of processing (the second initiated by apache's internal redirect function), one for /myfolder/index.php and the second for /cgi-bin/php5.cgi/myfolder/index.php?

Personally, I'd switch configuration...

Is r->uri changed, too? You can check that with a redirect to test.com:

RewriteRule ^ http://www.test.com/?%{REQUEST_URI}__%{REQUEST_FILENAME} [R,L]

[edited by: jdMorgan at 6:57 pm (utc) on Aug. 10, 2009]
[edit reason] Delinked to show underscores in query [/edit]

DerekH




msg:3968869
 7:19 pm on Aug 9, 2009 (gmt 0)

Well, my problem is that I'm right on the limit of my understanding of what's going on, and I can't log the htaccess (I have no rights).

I found a neat trick where one can leap out of the htaccess file with a redirect to another site with some of the arguments of the parsing on show in the URL. Which I've tried...
Certainly if I browse
mysite.com/index.html (which does not exist), it changes it to
mysite.com in the browser, and serves it fine from the php index file.
And subfolders mysite.com/myfolder/ get served properly in their bare form.
But because I use Dreamweaver, all my links have an index.php put on the end (or I can't check for broken links), and that's the ones that fail.

It's merely the parsing of the php files that's wrong.
It *looks* like the first stab that my htaccess gets of myfolder/index.php is after it's been translated to
cgi-bin/php5.cgi/myfolder/index.php, which is why I can't strip it just the php bit.
It *looks* like I get hold of the URL *after* it's been rewritten, and the Apache documentation implies that a php file is routed to the cgi-bin folder by a rewrite.
So it *looks* like the first sniff I get of it is when it's destined for the PHP processor, not the URL as presented by the user.

I guess I could search for cgi-bin/php5.cgi/ and for index.php and strip them BOTH off, and then send it round the loop again, but my command of htaccess and the difficulty of debugging it scares me off.

I was, I guess, secretly hoping someone would say "Ah yes, PHP and CGI always works like that, and here's how to fix it"

:-)
DerekH

Caterham




msg:3968888
 8:36 pm on Aug 9, 2009 (gmt 0)

"Ah yes, PHP and CGI always works like that

No, it doesn't.

So with a request of /myfolder/index.php and

RewriteRule ^ "http://www.test.com/?%{REQUEST_URI}__%{REQUEST_FILENAME}" [R,L]

in place (instead of other rules) you're redirected to test.com?/cgi-bin/php5.cgi__/physical/path/to/cgi-bin/php5.cgi

?

DerekH




msg:3968912
 9:40 pm on Aug 9, 2009 (gmt 0)

No, if I request h#*$!://www.mydomain.co.uk/folder/file it seems that my htaccess gets given a prepackaged
/cgi-bin/php5.cgi/folder/file
or at least that seems to be the file at the entry point into my .htaccess...

Sorry to be so vague - I'm a newbie at this...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved