Forum Moderators: phranque

Message Too Old, No Replies

.htaccess url problems

htaccess 301 redirect

         

frogz

4:26 pm on Dec 26, 2008 (gmt 0)

10+ Year Member



Hello, I am new here and have been using your website as a reference for information. Thanks for all the help you are providing us! I decided to sign up!

My question,


Options +FollowSymLinks
RewriteEngine on
RewriteRule index-post_id-(.*)\.htm$ index.php?post_id=$1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subdir/subdir/index\.php\?topic_id=([0-9]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/subdir/subdir/index-topic_id-%1.htm [R=301,L]

as you may have guessed, I am redirecting from dynamic urls.
the code above seems to work but it leaves a trailing ?topic_id=1234
behind the url. so the url looks like:

http://www.example.com/subdir/subdir/index-topic_id-1234.htm?topic_id=1234

it seems to work except for the trailing "?topic_id=1234" at the end of the url?
could you please direct me in the right way to rid the "?topic_id=1234" at the end of the url?

jdMorgan

4:35 pm on Dec 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a "?" to the substitution URL to clear the query string. Also suggest you use a more-specific pattern in the first rule for efficiency"

Options +FollowSymLinks
RewriteEngine on
RewriteRule index-post_id-[b]([^.]+)[/b]\.htm$ index.php?post_id=$1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subdir/subdir/index\.php\?topic_id=([0-9]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/subdir/subdir/index-topic_id-%1.h[b]tm? [[/b]R=301,L]

Jim

frogz

4:48 pm on Dec 26, 2008 (gmt 0)

10+ Year Member



Thank you for your timely response, I really appreciate it.
I will add the ? at the end to clear the query, as for adding more specific pattern to the first rule, can you elaborate?

my url patterns are this:


domain.com/subdir/subdir/index.php?top_id=(always numbers here)
domain.com/subdir/subdir/index.php?post_id=(always numbers here)
domain.com/subdir/subdir/index.php?forum_id=(always numbers here)
domain.com/subdir/subdir/index.php?cat_id=(always numbers here)

I was going to try to eliminate one of those subdir's as well in the rewrite. (one step at a time)

after combing for hours, the code above in my original post is the best I could piece together.

again, thank you for your timely response, and your help. It is much appreciated.