301 redirect - requestion

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 17 Apr 2014, 11:08

301 redirect - requestion

16 Jul 2014, 15:04

Hi,

We in our web site have category page and url will be like below
http://www.websiteurl.com/category.aspx?c=vegetables

After that we added helicon 3.0 software then we added below code in .htaaccess file.
RewriteRule /([^/]*)/c/([^/]*)/ /Category\.aspx\?c=$2 [I]
RewriteRule /([^/]*)/c/([^/]*)/([^/]*)/ /Category\.aspx\?c=$2 [I]
RewriteRule /([^/]*)/c/([^/]*)/([^/]*)/([^/]*)/ /Category\.aspx\?c=$2&$3=$4 [I]

Now we were able to use friendly url like below

http://www.websiteurl.com/vegetables/c/vegetables/
http://www.websiteurl.com/fruits/c/fruits/

This is working fine without any issue, but now I am not able to do the 301 redirects for vegetables category to vegetables-new category.

I tried below and it is not working.

RewriteRule /category.aspx?c= vegetables /vegetablesnew/c/vegetablesnew/ [L,R=301]
RewriteRule /vegetables/c/vegetables/ /vegetablesnew/c/vegetablesnew/ [L,R=301]

Do you have any suggestion?

Chinna.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: 301 redirect - requestion

17 Jul 2014, 23:20

Hello,

We'd suggest using the following:

Code: Select all
RewriteCond %{QUERY_STRING} ^c=([^&]+)$ [NC]
RewriteRule ^[^/.]+\.aspx$ /%1/c/%1/? [NC,R=301,L]


Regards
Andrew

User avatar
Posts: 5
Joined: 17 Apr 2014, 11:08

Re: 301 redirect - requestion

21 Jul 2014, 11:41

Andrew,

I added below code in my .htaaccess file

RewriteCond %{QUERY_STRING} ^c=([^&]+)$ [NC]
RewriteRule ^[^/.]+\.aspx$ /%1/c/%1/? [NC,R=301,L]

RewriteRule /category.aspx?c=vegetables /vegetablesnew/c/vegetablesnew/ [L,R=301]
RewriteRule /vegetables/c/vegetables/ /vegetablesnew/c/vegetablesnew/ [L,R=301]


Now this url "/category.aspx?c=vegetables" is redirecting to this url "vegetablesnew/c/vegetablesnew/"
But this url "/vegetables/c/vegetables/" is not redirecting.

How do I redirect one friendly url to another friendly url?

Chinna.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: 301 redirect - requestion

21 Jul 2014, 23:39

Hm... is there a patter for redirects from one friendly URL to another?
Do we really need the middle stage?

Regards

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: 301 redirect - requestion

23 Jul 2014, 13:20

Won't the earlier rule cause /vegetables/c/vegetables to be rewritten to category.aspx?c=vegetables?
So the 301 rule won't be hit with the right URL to trigger.

You'd need to put the 301 rules *before* the existing rewrites.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: 301 redirect - requestion

23 Jul 2014, 18:39

I agree with ChickPea, we need to take the order of the rules into the account.

Regards

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: 301 redirect - requestion

23 Jul 2014, 18:39

I agree with ChickPea, we need to take the order of the rules into the account.

Regards

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests