views:

301

answers:

2

Is this valid and correct?

RewriteRule ^myOldPage.html$ /index.php#info [R]

I'm specifically interested about the #info part.

A: 

Although it looks correct, I have a strange feeling this won't work.

The browser needs to know about the #anchor. The server and mod_rewrite may well just ignore it.

If it doesn't work I guess you could do something like..

RewriteRule ^myOldPage.html$ /index.php?info=true [R]

and then in the php output a piece of javascript to do the anchor jump.

adam
+2  A: 

Yes. That's a valid 301 redirect (the HTTP standard allows for any valid URI to be provided as the redirect).

Now the caveat: Not all search engines may love the redirect. Google does a fantastic job of handling anchor tags (they even have a patent on this), while others will completely ignore them. As long as that's not an issue, the redirect is technically valid.

Update: If you're having trouble with mod_rewrite, try the NE (no escape) flag to prevent the # symbol from getting encoded:

RewriteRule ^myOldPage.html$ /index.php#info [R,NE]
Chris Pebble
thanks! I was just coming back here to say about how it didn't work because of the # getting encoded...
nickf