Forum Moderators: phranque

Message Too Old, No Replies

.htaccess RedirectMatch help

         

RachelA

10:11 am on Apr 25, 2009 (gmt 0)

10+ Year Member



I'm a complete beginner at this, I was wondering if someone could please let me know if it were possible for this url:

[site.com...]

to be forwarded to this:

[site.com...]

With the "###" being a varying number...

I've looked at many tutorials but hours later I've gotten nowhere!

Thanks in advance for any help.

g1smd

10:23 am on Apr 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does the user get redirected to the new URL? or do you want a rewrite so the user continues to see the same URL they requested?

Both are possible, and it is very easy if the '###' part is the exact same number on both of them.

You'll need a

RewriteCond
to look at
QUERY_STRING
and a
RewriteRule
to do the actual work - but do you need a redirect or a rewrite here?

RachelA

10:26 am on Apr 25, 2009 (gmt 0)

10+ Year Member



Thank you so much for your quick response!

I would like the user to get redirected to the url. And yes the ### is the same number for the redirected page.

Thanks again!

g1smd

10:30 am on Apr 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need
[R=301,L]
on the end of the rule, and the target URL of the redirect will need to state the protocol and hostname as well as the path and parameters.

There's quite a lot of prior example code for doing similar stuff to that. Post your best effort code back here, using the clues above, as a basis for discussion.

RachelA

10:37 am on Apr 25, 2009 (gmt 0)

10+ Year Member



I really appreciate your help.. I've used a sample code as a template for this, but its structure was very different so I'm not sure if I've set it up correctly:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subfolder/\$
RewriteCond %{QUERY_STRING} ^value=click&class=([0-9]*)$
RewriteRule ^(.*)$ [site.com...] [R=301,L]

for [site.com...] to [site.com...]

[edited by: RachelA at 10:38 am (utc) on April 25, 2009]

g1smd

10:42 am on Apr 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's several 'right' ways to do it, and very many more 'wrong' ones. This will probably be sufficient:

RewriteEngine On
RewriteCond %{QUERY_STRING} [b]&?[/b]value=click&class=([0-9][b]+[/b])[b]&?[/b]
RewriteRule ^[b]subfolder/[/b](.*)$ http://www.site.com/[b]$1[/b]?id=[b]%1[/b] [R=301,L]

Be aware that it only responds to the parameters being in a particular order. If they are in a different order in the request, the rule will fail to run.

Does the

'value=click'
parameter *have* to be present, for the redirect to be needed? You need to think that through a bit more.

I also changed it so that the

class
parameter cannot be blank. It must have one or more digits within. Is that correct for your application?

I don't know if you also need to carry over any filename path part. I did include that, above, and omitted it below:

RewriteEngine On
RewriteCond %{QUERY_STRING} [b]&?[/b]value=click&class=([0-9][b]+[/b])[b]&?[/b]
RewriteRule ^[b]subfolder/[/b] http://www.site.com/?id=[b]%1[/b] [R=301,L]

You need to think about what happens when someone requests a subtly wrong URL. Do you want to redirect it, or make it fail as a 404 error? You will need to test what the code actually *does* with that request, and amend the code to fit what you actually need it to do.

RachelA

11:09 am on Apr 25, 2009 (gmt 0)

10+ Year Member



The second code worked perfectly! I can't thank you enough for your help.. I don't know much about the script that creates the urls, but I tried entering a wrong url and it just re-directed back to my home page by itself, which is perfect for me.

Thank you so much again for taking the time out to help me, I really appreciate your time.

Take care :)

network

3:52 pm on May 12, 2009 (gmt 0)

10+ Year Member



Can you redirect URLs using a Redirect 301?

Example;

[mysite.com...] needs to be redirected to a secure ssl certificate version of the site which has the address of [mysite.com...]

Would redirecting all traffic be possible by using a .htaccess redirect 301 by using code:

redirect 301 /http://www.mysite.com/https://mysite.com

and then saving the .htaccess in the ROOT folder on an Apache Server?