Forum Moderators: phranque

Message Too Old, No Replies

Help with rewriterule

         

ppro

10:19 am on May 25, 2007 (gmt 0)

10+ Year Member



I need a rewriterule that redirects these urls:

website.com/smf/index.php?topic=237.msg1307#msg1307

to these ones:

website.com/component/option,com_smf/Itemid,27/topic,237.msg1307/#msg1307

I have tried many things using rewritecond query string, but I haven't succeeded.

Thank you for your help

jdMorgan

2:54 pm on May 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best effort as a basis for discussion -- or start with the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

ppro

3:39 pm on May 25, 2007 (gmt 0)

10+ Year Member



Ok, sorry. I think I've managed to make it work with this rule:

RewriteCond %{QUERY_STRING} ^topic=([^\#]+)$
RewriteRule ^smf/index\.php$ /component/option,com_smf/Itemid,27/topic,%1/? [R=301,L]

What do you think?

jdMorgan

7:42 pm on May 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks OK, except that it appears have no provisions for the #msg1307 on the end of the URL, contrary to your desired-behaviour description.

Also, it depends on what you are trying to do: If these dynamic URLs no longer exist on your site, then this is the right approach. But if you're still using a script to generate content for them, then the proper approach is:

  • Change the links on your pages to use the static-looking URLs
  • Internally rewrite static URLs, when requested from your server, to the script
  • Externally redirect only direct client requests for the dynamic URL to the static URL

    Step 3 is similar to what you are doing now, except that you must add a check of the sever variable %{THE_REQUEST} in order to differentiate between direct client requests for dynamic URLs, and those that occur as a result of the internal rewrite described in step 2.

    See [webmasterworld.com...] for more info

    Jim

  •