0

I'm struggling with an Apache rewriterule. I need to do the following:

Redirect permanently:

http://domain.com/folder/viewer/data/settings.xml?prevent_cache=4760

to

http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=4760

I've got the code below, it works without the url parameters but I can't seem to get it to work with parameters. Am i missing something?

RewriteCond %{QUERY_STRING} ^prevent_cache=([0-9]*)$
RewriteRule ^/folder/viewer/data/settings.xml$ http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R=301,L] 

Cheers

Shaun

Shaun Perry
  • 159
  • 1
  • 2
  • 12

2 Answers2

1

The only error I can see, is the leading slash / in the RewriteRule pattern. This should be

RewriteCond %{QUERY_STRING} ^prevent_cache=[0-9]*$
RewriteRule ^folder/viewer/data/settings.xml$ /siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R,L]

You don't need to append the query string to the substitution URL, because this is done autmoatically.

When everything works as you expect, you can change R to R=301. Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

I can. Here are the rewrite condition and rule that you're looking for:

# once per htaccess file
RewriteEngine on

RewriteCond %{QUERY_STRING} prevent_cache=([0-9]*)
RewriteRule ^folder/viewer/data/settings.xml http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=%1 [R=301,L]

But please considered this answer about the [R=301] flag: https://stackoverflow.com/a/15999177/2007055

Community
  • 1
  • 1