Welcome to WebmasterWorld Guest from 54.198.179.85

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RedirectMatch 301

     
10:28 pm on Jan 14, 2004 (gmt 0)

New User

10+ Year Member

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


I'm trying to get
[domain.com...]
to redirect to
[domain.com...]

So far I have this:

RedirectMatch 301 ^(.*)cgi-bin/file.cgi?s=(.*)&v=(.*)$ $1subdir/$2/$3

Even if the code worked, it wouldn't change the .zip to .html, so I need help with that too. The original file extension won't always be .zip, but it will be three characters. The line is in the .htaccess file in the home html directory.

3:04 am on Jan 15, 2004 (gmt 0)

New User

10+ Year Member

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


Well, my other RedirectMatch lines work, but not this. I've edited the line many times, but I'm still getting nowhere.
9:26 am on Jan 15, 2004 (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


sonik,

"?" is a special character when used in a regular-expressions pattern. If you wish to match a literal question mark, as you do in your RedirectMatch pattern, you need to precede it withj a "\"


RedirectMatch 301 ^(.*)cgi-bin/file.cg[b]i\?s[/b]=(.*)&v=(.*)$ $1subdir/$2/$3

There may be other problems, but that one would stop your code from working.

Jim

9:23 pm on Jan 15, 2004 (gmt 0)

New User

10+ Year Member

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


Well, this is odd. When I preceded the? with a / there was no change. But when I replace the /? with an A and changed the URL I'm typing in the browser accordingly, just to make sure everything else works, it redirected correctly. So everything except for escaping the? correctly is working. Any ideas?
9:56 pm on Jan 15, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 1, 2003
posts:120
votes: 0


It's backslash (\), not forward slash (/).
10:00 pm on Jan 15, 2004 (gmt 0)

New User

10+ Year Member

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


Oops, my mistake. I had it right in the .htaccess file though, but not here :)
4:43 am on Jan 16, 2004 (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


Hmmm...

Can you try using mod_rewrite instead? I'm sure you can do what you need using mod_rewrite, but the question is whether your can use mod_rewrite on your server... Is it installed and do you have your permissions set? - That's the question.

Jim

4:52 am on Jan 16, 2004 (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


sonic,

If you can use mod_rewrite, the following code should be equivalent to RedirectMatch 301 ^(.*)cgi-bin/file.cgi\?s=(.*)&v=(.*)$ $1subdir/$2/$3:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^s=([^&]*)&v=(.*)$
RewriteRule ^([^/]*)/cgi-bin/file\.cgi$ /$1/subdir/%1/%2? [R=301,L]
5:24 am on Jan 16, 2004 (gmt 0)

New User

10+ Year Member

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


mod_rewrite does work on the server. The reason I want the 301 Redirect is so that requests to the old pages on file.cgi ...mostly links from google... will be redirected to the new URL. And hopefully google would change their listing to the new URL.
5:29 am on Jan 16, 2004 (gmt 0)

New User

10+ Year Member

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


I know this line would work if I could correctly escape the? character.

RedirectMatch 301 ^(.*)cgi-bin/file.cgi\?s=(.*)\.(.*)&v=(.*)$ $1subdir/$4/$2.html

5:50 am on Jan 16, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 1, 2003
posts:120
votes: 0


I don't know specifics of RedirectMatch. But try using . instead -- i.e. cgi-bin/file.cgi.s=

Dot means any character, so it'll be a bit broader, but will solve the problem.

6:17 am on Jan 16, 2004 (gmt 0)

New User

10+ Year Member

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


Still didn't work :( I tried (.*) also.
8:13 am on Jan 16, 2004 (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


sonik,

The mod_rewrite code I posted is an exact replacement for your Redirect 301 directive. The [R=301] in the RewriteRule forces an external 301 Redirect, and the [L] flag forces the redirect to occur immediately without any further mod_rewrite processing.

Unless I typed it wrong, it should do exactly the same thing as you intended to do with your original code.

Jim