homepage Welcome to WebmasterWorld Guest from 54.163.91.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RedirectMatch 301
sonik




msg:1513639
 10:28 pm on Jan 14, 2004 (gmt 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.

 

sonik




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

Well, my other RedirectMatch lines work, but not this. I've edited the line many times, but I'm still getting nowhere.

jdMorgan




msg:1513641
 9:26 am on Jan 15, 2004 (gmt 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

sonik




msg:1513642
 9:23 pm on Jan 15, 2004 (gmt 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?

andrew_m




msg:1513643
 9:56 pm on Jan 15, 2004 (gmt 0)

It's backslash (\), not forward slash (/).

sonik




msg:1513644
 10:00 pm on Jan 15, 2004 (gmt 0)

Oops, my mistake. I had it right in the .htaccess file though, but not here :)

jdMorgan




msg:1513645
 4:43 am on Jan 16, 2004 (gmt 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

jdMorgan




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

sonik




msg:1513647
 5:24 am on Jan 16, 2004 (gmt 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.

sonik




msg:1513648
 5:29 am on Jan 16, 2004 (gmt 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

andrew_m




msg:1513649
 5:50 am on Jan 16, 2004 (gmt 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.

sonik




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

Still didn't work :( I tried (.*) also.

jdMorgan




msg:1513651
 8:13 am on Jan 16, 2004 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved