Forum Moderators: phranque

Message Too Old, No Replies

using mod_rewrite to hide urls-- they redirect, but why not hide?

rewrites to change the url without the browser knowing

         

broniusm

5:26 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



I use mod_rewrite to rewrite urls to clean, "seo friendly" urls like everyone else. What what I couldn't figure out is why my urls came out looking like the rewritten request as opposed to the clean one that was requested.

For me, my solution was to simply remove the complete url and change only the changed portion (likened to relative paths as opposed to absolute).

RewriteRule ^monitor([0-9]+) htp://same-domain/apps/docketscroller/showdocket-js2.php?monitorid=$1 [nc]
becomes
RewriteRule ^monitor([0-9]+) showdocket-js2.php?monitorid=$1 [nc]

What I don't really get is why? And is there a better/another way?

jdMorgan

3:38 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't answer your question directly, but be aware that mod_rewrite can do three main things:

1) Generate an external redirect.
2) Change the filepath associated with a requested URL -- an internal rewrite.
3) Create a proxy through-put (not relevant to this thread).

The syntax of the rule determines which of those first two it will do.

External redirect:


RewriteRule ^foo\.php$ http://www.example.com/bar.php [R-301,L]

Internal rewrite:

RewriteRule ^foo\.html$ /foo.php?req=foo [L]

Note that I used the [L] flag on both, just out of habit. But it's a good habit, because if you don't use that flag, then *all* rules will be processed, even if the first one matches.

This may in fact be a cause of your problem. For example, if you took the [L] flags off my rules above, and then reversed their order, the redirect would 'expose' the internal rewrite.

Jim

broniusm

5:33 am on Apr 1, 2006 (gmt 0)

10+ Year Member



Hmm.. now at home for the weekend, I am not tempted to experiment. But judging on what you said about the [last¦L] directive, perhaps what's happened in my case (wihtout the L) was:
- url gets passed in,
- url gets rewritten (without an L),
- rewritten url gets passed in and "processed" (but, not matching any rules, passes clean through)

Funny how something that's been around and documented for years, we can still hypothesize about like it's an alien mineral found in a field.

Thanks (cross-post) again for your input jdM.

-bronius