Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite single forum post to static page

         

zealer

5:28 am on Dec 15, 2013 (gmt 0)

10+ Year Member



Hi all,
I am trying to enforce a 301 (moved permanently) redirect on a forum topic of mine to a static HTML page.

Old URL: forums/index.php?topic=4.0

New page: /static-page.html

I don't need any ID's or anything, I just want that one topic (?topic=4.0) to redirect to /static-page.html

I just cannot get it to work.
I have come up with this
RewriteCond %{QUERY_STRING} ^topic=4.0$
RewriteRule ^(.*)$ /static-page.html [R=301,L]


But when trying it out the URL becomes /static-page,html?topic=4.0

How can I remove that?

lucy24

6:02 am on Dec 15, 2013 (gmt 0)

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



You forgot to put a ? at the end of the target to clear the existing query string.

The other thing you forgot is the pattern. Sure .* will work but it's way overkill. Anchors are never necessary in this configuration. But the main issue is that you should give only the exact URL that will actually carry this specific query. In this case that would be

^forums/(index\.php)?$


Otherwise the server has to stop and evaluate the condition on every single request for every file of any kind anywhere. I made the "index.php" optional because I devoutly hope it isn't really part of your URL.

The Condition as you have it, with anchors, will only work if there is nothing else in the query string. Otherwise you'd have to leave off the anchors. Finally: forgetting to escape a literal period in a pattern is seldom lethal, but it's never a good habit. The most hair-splittingly exact form of your RewriteCond is

(^|&)topic=4\.0($|&)


But you may not need to get that fancy. It depends on what the query strings-- again, for only this specific path-- look like.

,html

I'm going to assume the comma was a typo.

g1smd

12:58 am on Dec 17, 2013 (gmt 0)

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



All of the above, and...

Add protocol and hostname to the redirect target.