Forum Moderators: phranque

Message Too Old, No Replies

redirect rewrited page

         

orsopoeta

1:09 pm on May 25, 2011 (gmt 0)

10+ Year Member



hi all!
i've got a apache-question it feels me crazy :-/

...

i've got this sample rule:

RewriteRule ^stories\/([0-9]+)\/(.*)+ stories/index.cfm?id=$1


and this works perfect.

now, i would redirect one page (just rewrited) to another:

Redirect 301 /stories/2000/title-of-story http://host/stories/2001/another-story


but apache redirect to

http://host/stories/2001/another-stories?id=2000


appending to url the query string "?id=2000"

how can i remove it?

many thanks! :-)

wilderness

2:45 pm on May 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



mixing mod_alias (Redirect) and mod_rewrite (RewriteRule) is a bad practice and will expose URL's which you do not desire exposed, as well as providing unpredictable comparability.

orsopoeta

3:20 pm on May 25, 2011 (gmt 0)

10+ Year Member



you are right wilderness,
but i tried to use redirect because whith mod_rewrite i'm not able to match the first url this mod_rewrite...

this

RewriteRule ^stories/2000/title-of-story$ stories/2001/another-story

doesn't work :-/

any idea?

wilderness

6:18 pm on May 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



These Rewrites are not my forte.
The only rewrites that I've ever accomplished have been simple ".html" URL's.

Sorry.

lucy24

8:15 pm on May 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Starting reminder: using "example.com" will keep your visible input from turning into an invisible url.

RewriteRule ^stories\/([0-9]+)\/(.*)+ stories/index.cfm?id=$1
and this works perfect.

Woo Hoo, another javascript-speaker. You don't need to escape forward-slashes in htaccess; they don't mean anything.

now, i would redirect one page (just rewrited) to another:

Redirect 301 /stories/2000/title-of-story http://example.com/stories/2001/another-story

but apache redirect to

http://example.com/stories/2001/another-stories?id=2000

appending to url the query string "?id=2000"

You mean the self-same "?id=2000" you captured up above in the first line? Are you leaving out a step? (In your post, I mean, not in the htaccess.)

This is the peril of merging rewrite and redirect. Either one by itself can do bad things if you have too many different rules, and now you're multiplying the risk. I do too. Some things just don't ### work any other way. So you have to figure out very, very carefully what things are being done in what order, because it doesn't always match the physical arrangement of your htaccess page.

RewriteRule ^stories/2000/title-of-story$ stories/2001/another-story

doesn't work :-/

It can't. The $ means "this is the end of the input", while the string you've given never is the end of the input. Rewrite thinks everything ends with an extension, like .html, even if it's invisible to the naked eye. What happens if you do it without the ^ and $ anchors?

g1smd

8:34 pm on May 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't mix Redirect and RewriteRule in the same file. Use RewriteRule for all of the rules (both redirects and rewrites).

Add the [L] flag to every RewriteRule.

You'll need to use a preceding RewriteCond to detect QUERY_STRING data.

Redirects must include the protocol and domain name in the target URL and the [R=301,L] flags.

To clear the query string add a question mark after the rule target.

List the redirects in order from most specific to least specific, the last usually being the canonical non-www to www redirect. List all redirects before the rewrites. List the rewrites from most specific to least specific.