Forum Moderators: phranque

Message Too Old, No Replies

301 rewrite a variable url to a static url

301 rewrite a variable url to a static url

         

kflm

9:53 pm on Nov 22, 2006 (gmt 0)

10+ Year Member



Have a small site with a bunch of urls like this:

/index.cfm?action=related&linkid=26

We are moving to a static html system, so for the above example the new page would simply be:

/newlink.html

We don't have a lot of pages, under 20, so I planned to do just a simple Redirect rule for each url in the .htaccess file. However, I can't get it to work. Here's what I did:

redirect 301 /index.cfm?action=related&linkid=26 [newsite.com...]

I have a feeling it's got something to do with the dynamic variables in the original url.

Anyone have any ideas?

kflm

1:24 pm on Nov 23, 2006 (gmt 0)

10+ Year Member



I ended up using this:

RewriteCond %{QUERY_STRING} ^action=related&linkid=26$
RewriteRule ^index.cfm$ /newpage.shtml? [R=301,L]

I learned that anything after the? in the URL is not read by redirectmatch or mod_rewrite. In mod_rewrite, you have to use the QUERY_STRING variable to access it.

I also needed to drop the query string in the new forwarded url....that's what the? is after the new url