Forum Moderators: phranque
Both sites I tested are on the same server and httpd.conf settings are the same for each.
I'm just trying to redirect without showing that the url changed. One site will do it and the other shows the url that you're redirected to.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule .* /country/us.php [L]
order allow,deny
allow from all It redirect everyone from the US to this page.
One site shows the actual page url and the other site shows the url you entered before being redirected.
However, there is a potential 'infinite loop' or 'dead-loop' problem. Consider changing the rule to:
RewriteRule !^country/us\.php$ /country/us.php [L] And note that for purposes of accurate discussion, your rule is intended to do an internal URL-to-filename rewrite, not an external URL-to-URL redirect.
Jim
About the url-to-filename, I'll have to look up exactly what that means.
# Rewrite requests for x.html to y.html
RewriteRule ^x\.html$ /y.html [L]
#
# Redirect request for x.html to y.html
RewriteRule ^x\.html$ http://www.example.com/y.html [R=301,L]
An external redirect sends an HTTP response to the client (e.g. browser or robot) that tells it to issue another HTTP request and ask for the resource it wanted using a different URL. So a redirect rule says, "If we get a request for URL 'x.html', redirect the client to http://www.example.com/y.html". When a client browser requests this new URL, it changes the URL in its address bar.
So, your problem is that on one server, your RewriteRule which is intended to do an internal rewrite is resulting in an external redirect.
Without knowing what other rules you use in your various .htaccess files and in httpd.conf, conf.d, etc., it's hard to tell what might be going on. The first thing I would check is to be sure that UseCanonicalName is off, or that the ServerName is exactly the one that you use as your canonical name. Otherwise, you may get into trouble with a conflict between the defined canonical name of the server and any RewriteRules intended to force a different canonical name.
Jim
[edited by: jdMorgan at 4:35 am (utc) on Aug. 10, 2008]
I just figured out what the problem was and it seems to work now.
On the /country/us.php page there is php code that looks for a certain string in the url. If that string is set then it does a header redirect based on the string info, if it's not set then it redirects to a default page for that country.
So my little piece of php was the whole problem. Sorry for wasting your time, it's another learning experience I guess.