Forum Moderators: phranque
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?
ie can you ping www.mydomain.com and have it resolve to the proper IP?
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)"
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>
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.
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]
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