Forum Moderators: phranque

Message Too Old, No Replies

Immediate Apache Help Needed

         

rcaubin

9:15 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



I'm a total newbie to Apache, but I need a quick fix.

I have a php script hosted on a linux server.

I'm trying to call the script from an external domain.

The only problem is that I'm getting an http code 406 error because my calling domain name has a www. in front of the rest of the domain and my linux server won't accept that.

I tried calling the script from the same url, but without the www. and it worked fine.

Is it possible to do a server side re-write:

If calling domain contains www.
then remove www.

If so, can some expert here provide the code and in which file do I put it in?

vabtz

9:16 pm on Mar 1, 2005 (gmt 0)



does your DNS record have an entry in it for www?

ie can you ping www.mydomain.com and have it resolve to the proper IP?

rcaubin

9:42 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Yes.

I looked over my logs where my script is hosted.

Here's the errors I'm getting
(BTW: www.domain.com is the domain that is calling the script, if the www. isn't there, the script works fine)

[01/Mar/2005:16:33:14 -0500] "GET /script1.php HTTP/1.1" 200 2463 "http://www.domain.com" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"

[01/Mar/2005:16:33:15 -0500] "GET /script2.php?location=http%3A//www.domain.com/page.html&referrer= HTTP/1.1" 406 281 "http://www.domain.com" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"

sitz

2:34 am on Mar 2, 2005 (gmt 0)

10+ Year Member



Are you using Namebased virtualhosting? If so, you'll need to make sure that both the 'www.domain.com' and 'domain.com' are listed in the proper <VirtualHost> block:

NameVirtualHost 111.22.33.44:80


<VirtualHost 111.22.33.44:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /path/to/docroot

(other directives here)
</VirtualHost>


If all else fails, yes, you can use mod_rewrite to redirect the request to 'domain.com', using something like the following in your httpd.conf:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond ^(.*) http://domain.com$1 [L,R]

You really shouldn't need to resort to the redirect, though. Smells like a minor apache configuration issue, or possibly an application/application config issue.

jdMorgan

2:59 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

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

Jim

rcaubin

3:40 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



will the above code allow my server to rewrite the urls of any incomming requests from other domains to remove www. from the domain name?

Remember, I'm not trying to rewrite the hosting domain name, I'm trying to have the hosting domain rewrite incomming data before it's processed.

jdMorgan

6:10 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you trying to rewite the query string part of this request?

GET /script2.php?location=http%3A//www.domain.com/page.html&referrer=

If so, then use RewriteCond %{QUERY_STRING} to test and create a back-reference to the part of the query string you want to keep. Using your example with the 406 response:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^location=http(:¦\%3A)//www\.([^&]+&referrer=.*)
RewriteRule ^script2\.php$ /script2.php?location=http://%2? [L]

This code is for use in .htaccess. If you want to use it in httpd.conf, add a leading slash on the RewriteRule pattern. It also assumes that the query string variables are always in the same order.

Replace the broken pipe "¦" character with a solid pipe character before trying to use this code.

This error appears to be caused by a problem in your script, since a 406 response indicates that your server cannot provide content in the format requested by the client. There's no obvious reason why the content-type should change depending on whether there is a "www" in the request query string.

Jim