Forum Moderators: phranque

Message Too Old, No Replies

Wildcard 301 redirects in very specific circumstance

Wildcards in htaccess for 301 redirect

         

Asia_Expat

4:13 am on Mar 8, 2007 (gmt 0)

10+ Year Member



This is a follow up post to a thread that is too old to reply to (system won't allow it). It's taken me ages to reply because I've been struggling with the problem for ages.

Here is the original post...

I have an Invision installation that I have modified to be search engine friendly. However, there is one particular dupe content issue I can figure a way around and I'm sure there must be a way to do it with htaccess. I just can't figure it out though so I hope someone will help me.
Below is an example of a topic URL...

www.example.com/forum/index.php?showtopic=2414&st=0

The last part ( &st=0 ) produces exactly the same page as...

www.example.com/forum/index.php?showtopic=2414

... and so I want to 301 redirect the first example to the second example... but ONLY if '&st=0' is present.

If...
www.example.com/forum/index.php?showtopic=2414&st=20
... is the URL, the redirect MUST NOT happen... I can't work this out, sorry. Please help :-)

Thanks.

The original thread is here...
[webmasterworld.com...]

The last line of the htaccess file was in place to produce a 404 error as Google was requesting pages that did not exist and my server was producing the homepage for those requests (bad dupe issues) but I'm pretty sure those requests have stopped now so I will remove the last line of that htaccess file, hopefully making it easier to find a solution to my original post.

My htaccess will now look like this...

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ h##p://www.example.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ h##p://www.example.com/ [R=301,L]

I'd be so very grateful if my question in the first post could be answered because I've been struggling with it for ages.

[edited by: Asia_Expat at 4:15 am (utc) on Mar. 8, 2007]

jdMorgan

1:16 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the exact situation you describe, allowing only the showtopic value to vary, I'd suggest:

RewriteCond %{QUERY_STRING} ^showtopic=([^&]+)&st=0$
RewriteRule ^forum/index\.php$ http://www.example.com/forum/index.php?showtopic=%1 [R=301,L]

Jim

Asia_Expat

1:31 pm on Mar 8, 2007 (gmt 0)

10+ Year Member



Thanks jdMorgan... as ever, concise and helpful.
I'll test this out shortly and tell you if it works.

Asia_Expat

3:05 pm on Mar 8, 2007 (gmt 0)

10+ Year Member



Well, on the face of it, everything appears to be OK and the specific 301 I described seems to be working perfectly on each topic... although I'm still testing to make sure it's not interfering with anything else.
If you have time, perhaps you could briefly tell me exactly the behaviour of the =%1
How is it placing the topic id? It's really very clever.

jdMorgan

3:22 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Standard mod_rewrite behaviour -- See [httpd.apache.org...]

Jim