tags:

views:

144

answers:

2

I'm trying to hard code a redirect on my site from a category based URL to a fixed URL.

The url structure is :

http://www.mysite.com/my-category-c-17_12.html 

And I'm trying to redirect that to:

http://www.mysite.com/my-static-category.php

Using the following redirect in my .htaccess file:

Redirect 301 /my-category-c-17_12.html http://www.mysite.com/my-static-category.php

I end up with:

http://www.mysite.com/my-static-category.php?cpath=17_12

Below my redirect, I also have the following line:

RewriteRule ^(.*)-c-([0-9_]+).html$ index.php?cPath=$2&%{QUERY_STRING} 

I'm not sure if that is what is causing it or not. Basically I want a way to strip the parameters from the redirected URL. Does anyone know how to deal with that? Thanks!

+1  A: 

If you already have mod_rewrite then why not just use it?

RewriteRule ^(.*)-c-([0-9_]+).html$ $1.php [R=301,L]
Ignacio Vazquez-Abrams
I'm only looking to rewrite specific URLs, not all URLs, so I don't want to change the behavior of the rest of the site. And this need to be a 301 because I'm just trying to keep old links in tact.
A: 

If you don't want a global rewrite (as per Ignacio Vazquez-Abrams's suggestion).. Instead of using the Redirect directive, just use RewriteRule. Something like (in full):

RewriteEngine on

# Limited redirects
RewriteCond %{REQUEST_FILENAME} my-category-c-17_12.html$ [OR,NC]
RewriteCond %{REQUEST_FILENAME} my-category-c-17_13.html$ [OR,NC]
RewriteCond %{REQUEST_FILENAME} my-category-c-17_14.html$
RewriteRule ^(.*)-c-([0-9_]+).html$ $1.php [R=301,L]

# Other rewrites
RewriteRule ^(.*)-c-([0-9_]+).html$ index.php?cPath=$2 [QSA,L]

You could then add other URLs to the RewriteCond to allow more URLs to be redirected.

Cez
Worked like a charm. Thanks.
You're welcome. Glad to help
Cez