Forum Moderators: phranque

Message Too Old, No Replies

Help with 301 Redirection

Need Help with 301 Redirection

         

asahmed

7:11 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



Hello,

I'm new to Redirections in Apache web server,

Can anyone tell me how to do the following:

I want to redirect:
[domain.com...]
To:
[sub.domain.com...]

Variable should stay the same, I only want a 301 permanent redirection from domain to subdomains just for that specific category.

Hope someone will help

asahmed

8:26 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



someone help please

jdMorgan

8:40 pm on Aug 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try searching this forum for that type of code -- It's been posted many times, including once already today [webmasterworld.com]. modify it to suit your needs, test it, and then ask any specific questions back here.

Please see our Apache Forum Charter for additional information.

Thanks,
Jim

asahmed

9:01 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



Thanks Jim,

I'm sorry I don't really understand this, I've searched but didn't get a solution..

I tried this:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^ product =1$
RewriteRule ^index\.php$ [sub.domain.com...] [R=301,L]

but the redirection is only done when the product id is '1' and it redirects to product '1%3f'

what I want is to pass a variable, i mean any numeric value should be redirected with the same value.

Hope you can help

Thanks

g1smd

9:16 pm on Aug 26, 2010 (gmt 0)

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



The %3f will be the stray question mark your rule adds on the end. It's there in your code.

In place of the '1' in the RewriteCond, use ([0-9]+) and then reference it using the %1 backreference in the rule target, in place of the hard-coded '1'.

asahmed

9:53 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



thanks! it works now

jdMorgan

9:54 pm on Aug 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In domain.com/.htaccess:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^product=
RewriteRule ^index\.php$ http://sub.domain.com/ [R=301,L]

and in sub.domain.com/.htaccess:

DirectoryIndex /index.php

This gets rid of the unnecessary "/index.php" in the sub.domain.com URLs, keeping only the query string (which passes through the above rule unchanged).

Jim