Welcome to WebmasterWorld Guest from 34.229.126.29

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Any ideas why this won't work

Htaccess redirect.

     
2:33 am on Aug 25, 2003 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7833
votes: 90


Replacing a script That is used on my site. Problem being there is a lot of traffic still finding it's way to the old script locations through search engines. Not only is the script location different but there is also a new variable to be added to the query string.

I have tried the following on my server and it does nothing.

RedirectMatch permanent ^/script.php?this=(.*) http:*/www.me.com/s/script2.php?foo=xxxx&that=(.*)

The variables "this" and "that" are the same variable but with a different name. The variable "foo" is fixed and is manualy inserted.

In my code http:*/ was simply used to prevent a link.

Any ideas why this wont work :)

Mack.

2:57 am on Aug 25, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


You need to use the result from the match, so you'd have to replace your second (.*) with $1, like so:


RedirectMatch permanent ^/script.php?this=(.*) http:*/www.me.com/s/script2.php?foo=xxxx&that=$1
3:33 am on Aug 25, 2003 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7833
votes: 90


Thanks for the reply. I tried as you suggested but no joy. I have a few other redirects on other lines and they all work ok. Not sure why this one.
Mack.
3:46 am on Aug 25, 2003 (gmt 0)

Moderator

WebmasterWorld Administrator buckworks is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 9, 2001
posts:5823
votes: 153


Something I had trouble with was that the word processor I was using to create my .htaccess files sometimes inserted invisible characters that were messing things up. Someone else found them for me.

It might be worth typing a totally fresh copy of that line in case there's a stray invisible character hiding in there that you're not aware of.

4:06 am on Aug 25, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


mack,

I don't think Redirect or RedirectMatch is query-string-aware. I tried a query-string Redirect years ago and never got it to work. The fix was to use mod_rewrite.

Jim

4:29 am on Aug 25, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


Jim's right.

Check this out:
[webmasterworld.com ]

5:55 am on Aug 25, 2003 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7833
votes: 90


Ok i now understand why it doesnt work.

Does anyone know what syntax woudl work via mod_rewrite.

Htaccess it definatly not my strong point

Thanks again for the replies.

Mack.

6:10 am on Aug 25, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


mack,

Try something like this:


RewriteCond %{QUERY_STRING} ^this=(.*)$
RewriteRule ^script\.php$ http:*/www.me.com/s/script2.php?foo=xxxx&that=%1 [R=301,L]

If you don't already have any other mod_rewrite code in your .htaccess file, you will need to precede the above with "RewriteEngine on" and possibly also with "Options +FollowSymLinks" although this latter is not always needed, and can sometimes mess things up. If both are required, the result would be:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^this=(.*)$
RewriteRule ^script\.php$ http:*/www.me.com/s/script2.php?foo=xxxx&that=%1 [R=301,L]

Try it without the Options directive first, and add it in if the rewrite doesn't work without it.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

6:42 am on Aug 25, 2003 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7833
votes: 90


Jim you've been a great help. Thanks very much.

Going to go try them now. will let you know how I get on.

Mack.

9:14 am on Aug 25, 2003 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7833
votes: 90


Worked very well.

Thanks again.

Mack.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members