Bojangles
Bojangles

Reputation: 101493

Rewriting old URLs to new, clean ones

I have me .htaccess file happily rewriting things like /conferences/details/21 to /index.php?pages=conferences&var1=details&var2=21.

I have Piwik tracking this site, which is showing up a lot of referrals from sites that haven't update their URLs (it's a very new site re-do) with URLs such as

http://www.domain.com/index.cfm?page=conference&intConferenceID=81

And

http://www.domain.com/index.cfm?page=conference&intConferenceID=88&type=conference

I'd like to rewrite them to /conferences/details/[numeric ID seen above].

I've tried this:

RewriteRule ^index.cfm?page=conference&intConferenceID=(\d+)/?$ /conferences/details/$1 [L,NC,QSA]

Obvisouly ignoring the second example. However, it gives me a 404 saying index.cfm can't be found.

What rewrite rule do I need to write to rewrite the above formatted links (the IDs change) to /conferences/details/[ID]?

Upvotes: 0

Views: 71

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You can extract the query string from RewriteCond:

RewriteCond %{REQUEST_URI} ^/index.cfm
RewriteCond %{QUERY_STRING} page=(.+)&intConferenceID=([^&]+)
RewriteRule . /%1/details/%2 [L]

Not sure where the "details" comes from based on the /foo/bar/21 -> /index.php?f=foo&b=bar&arg=21 rewriting.

Upvotes: 1

Related Questions