Welcome to WebmasterWorld Guest from 54.167.22.37

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

rewrite rule, 2 sites & 2 different results

     

Doood

7:37 pm on Aug 9, 2008 (gmt 0)

10+ Year Member



Why does the exact same rewrite rule produce different results when used on different sites?

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.

jdMorgan

1:15 am on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Rather hard to tell without seeing the code...

Jim

Doood

2:29 am on Aug 10, 2008 (gmt 0)

10+ Year Member



It's just basic stuff, nothing special.

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.

jdMorgan

2:51 am on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I can't see any reason why the two sites would behave differently here.

However, there is a potential 'infinite loop' or 'dead-loop' problem. Consider changing the rule to:

 RewriteRule !^country/us\.php$ /country/us.php [L] 

to prevent the script URL-path from being repeatedly rewritten to itself.

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

Doood

3:59 am on Aug 10, 2008 (gmt 0)

10+ Year Member



Yeah I stop the infinate loop by turning the rewrite engine off in the /country folder. You got on to me about that one other time, but I think this way has 3 or 4 times less rewrite processes. When you multiply that by 100 million per day it could make a difference.

About the url-to-filename, I'll have to look up exactly what that means.

TowerOfPower

4:30 am on Aug 10, 2008 (gmt 0)

10+ Year Member



The results of these rewrite rules could vary if there are other higher level .htaccess files present that are not identical, in the two site structures.

jdMorgan

4:33 am on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Simple: The two main forms of RewriteRule are an internal rewrite and an external redirect.

# 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 internal rewrite 'points' a request for a URL to a different file than it might resolve to without the RewriteRule. An internal rewrite says, "If we get a request for URL 'x.html', serve the file 'y.html' instead."

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]

Doood

3:15 pm on Aug 10, 2008 (gmt 0)

10+ Year Member



Oh so you were talking about my incorrect use of the word redirect when I'm actually doing a rewrite, gotcha.

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.

g1smd

7:38 pm on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



If you learnt something then it wasn't a waste of time. :-)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month