Forum Moderators: phranque

Message Too Old, No Replies

Non www to www works except for cgi-bin and below

         

StaceyJ

8:43 pm on Dec 15, 2010 (gmt 0)

10+ Year Member



I have this in my root htaccess file to send all non www requests to www.

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

It works fine on all subdirectories except the cgi-bin and its subdirectories. What am I missing? Do I need a second htaccess in the cgi-bin to control that? I'm kind of baffled. I do have a subdirectory in the cgi-bin with its own htaccess file that works for what it's supposed to, but I'm not sure what I need to do here to make this work. Any input would be greatly appreciated.

jdMorgan

4:18 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is most likely that your cgi-bin is an Apache "Alias" directory. That is, requests for any resource in the /cgi-bin URL-space invoke an Alias directive which rewrites them to a part of the filesystem not otherwise accessible to you.

If this is the case, then mod_alias will get invoked at the server config level for /cgi-bin requests, and your .htaccess file will not be executed. Therefore, no code in your file will have any effect.

One possible way out of this sack is to change all /cgi-bin links to something else. Then after your hostname canonicalization redirect has had a chance to work, you can internally rewrite those "something else" URL-path requests back to the /cgi-bin filespace. This solves the problem going forward, but provides no relief for old search listings or any remaining links that might still go to /cgi-bin -- either unintentionally or maliciously.

The same problem often occurs with aliased PHP script directories, so it is a fairly-common problem.

Jim

StaceyJ

4:52 pm on Dec 16, 2010 (gmt 0)

10+ Year Member



Thanks Jim! As soon as you mentioned Alias it clicked, I'm willing to bet you're right about that. So I was pulling my hair for nothing. I guess I'm stuck on that until I do get all the links changed over to remove cgi-bin from them as I'm working towards.

At this point if there weren't any decent SE rankings I'd be inclined to scrap the whole thing and move the script out of the cgi-bin and start over with SE and user friendly (and shorter) URL's to begin with. All the redirecting and rewriting that's required is getting mind boggling.

Thank you!

jdMorgan

5:12 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hang in there, and if you are doing both redirection and rewriting, be sure to check out the Proper order for htaccess [webmasterworld.com] thread in our Apache Forum Library. Getting the directives in strict correct order is critical to avoiding "a series of unfortunate events." The described framework will go a long way to keeping you out of trouble.

Jim

StaceyJ

5:20 pm on Dec 16, 2010 (gmt 0)

10+ Year Member



Thanks! And thanks for the link which I already had opened in one of many tabs from here. Invaluable!