How to rewrite a URL with htaccess?

Isn’t a 301 response “external?”

Yes.

Capt CSS,

Actually, NO!

The 301 status code tells browsers (and SE’s) that the redirection is permanent. The result, as far as mod_rewrite is concerned, is that you will view the redirection in the browser’s location box.

An “external” redirection is when you use the full URL in the redirection, i.e., http://subdomain.domain.com/whatever. The “external” part comes from the protocol (http://) and domain (subdomain.domain.com) used.

On the right track, albeit painfully, in this thread. To clarify, though, mod_rewrite only stops processing when it makes no matches (allowing Apache to serve the resultant {REQUEST_URI}). JM correctly stated that the Last flag simply tells mod_rewrite to restart its processing (“take it from the top” with the new {REQUEST_URI}).

Regards,

DK

An external redirect is any 3xx response. And Apache doesn’t require us to use the full URL do so.

PLEASE, learn something before making more erroneous comments here!

For example (straight from the documentation):

Redirect Directive: Sends an external redirect asking the client to fetch a different URL. The new URL may be either an absolute URL beginning with a scheme and hostname, or a URL-path beginning with a slash. In this latter case the scheme and hostname of the current server will be added.

redirect|R[=code] Forces an external redirect, optionally with the specified HTTP status code. Use of the [R] flag causes a HTTP redirect to be issued to the browser. If a fully-qualified URL is specified (that is, including http://servername/) then a redirect will be issued to that location. Otherwise, the current protocol, servername, and port number will be used to generate the URL sent with the redirect.

From Old to New (internal)
RewriteRule ^/foo\.html$ /bar.html

From Old to New (external)
RewriteRule ^/foo\.html$ /bar.html [R]

Whether we use a full URL or not has nothing to do with the term “external redirect.” An external redirect, quite simply, is any 3xx response.

It seems the problem is not in htaccess at all but the httpd.conf file.

For the application I’m developing it seemed a good idea to give each client a sub-domain

http://client.domain.com/

mostly a vanity thing but one which would allow each client to customize (skin) their account and not have to go through a common portal or landing page to get there. Later I found that if the sub-domain part of the url had a mistake the user would get a server not found error message. The solution was to create a wild-card (*) sub-domain. Then, provided the domain itself was correct, php would be able to deal with all the problems. I set it up and when testing I got some weird results. I had already set up two sub-domains. A url with www.client.domain.com acted different than a url with www.wildcard.domain.com. I think I tracked it down to the httpd.conf file. Being on a shared server I don’t have access to this file so I can’t be sure.

Thanks for all the help!