Forum Moderators: phranque

Message Too Old, No Replies

Strange mod_rewrite problem for simple redirect

Inserts full server's physical path into redirect

         

neodude

1:31 am on Nov 14, 2004 (gmt 0)

10+ Year Member



Windows XP SP1, Apache 2.0.44

DocumentRoot: E:\Webs\cfRoot\

\neodude\v5b\.htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /neodude/v5b
RewriteRule ^about$ about/ [R]
RewriteRule ^about/$ about.cfm

--

Effectively, I want:
http://localhost/neodude/v5b/about
to redirect externally to:
http://localhost/neodude/v5b/about/
that would interally redirect to:
http://localhost/neodude/v5b/about.cfm

The /about/ -> about.cfm part works.
However, the redirect from /about -> /about/ gives me:
http://localhost/E:/Webs/cfRoot/neodude/v5b/about/

If a remove the [R] from the RewriteRule ^about$ about/ [R], it works, albeit doing a totally internal redirect from /about -> /about/ -> about.cfm.

How come Apache includes the entire physical path into the request? Is there anyway I can force a redirect from /about to /about/ externally?

jdMorgan

7:57 am on Nov 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Neodude,

Welcome to WebmasterWorld!

> Is there anyway I can force a redirect from /about to /about/ externally?

No.

By definition, a redirect is a server-client-server transaction. The server sends the new URL to the client in a response with a 301 or 302 status header, and the client uses that URL to re-request the desired resource from the new URL. As such, the server must send the canonical URL to the client.

An internal rewrite is simply the substitution of a new filepath for the resource, and as such, it has to be local.

It sounds like you may have one of several common problems here, because "example.com" should always resolve to "example.com/". This is done by mod_dir, so check that mod_dir is loaded on your server.

A second problem comes up if you have UseCanonicalName on. This can sometimes cause trouble. Try setting it to off.

The third thing that often causes trouble is content-negotiation. If you have Options All or Options MultiViews set, and you don't need multiviews, turn them off.

I'm guessing at your ultimate goal here. It's not clear why you want or need two RewriteRules to accompish your stated goal.

Jim

neodude

12:23 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



mod_dir loaded: yes
UseCanonicalName: off
Options: Includes FollowSymLinks Indexes

--

if I take off this rule:

RewriteRule ^about$ about/

I get a 404 error for
[localhost...]

But OK for
[localhost...]

--

My ultimate goal(s) are:
1. all /about requests are redirected externally, so the user is aware, to /about/. To encourage good URL writing practises.
2. all /about/ requests interally rewrite to about.cfm. This is URL beautification.

Number 2 works now; its just that I can't force an external redirect for number 1.

Any possible solutions?

jdMorgan

6:36 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try it this way:

/neodude/v5b/.htaccess:


Options +FollowSymLinks
RewriteEngine on
RewriteBase /neodude/v5b
RewriteRule ^about$ http://www.yourdomain.com/about/ [R=301,L]

/neodude/v5b/about/.htaccess:

DirectoryIndex about.cfm

Jim