Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess重定向参数不起作用_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

.htaccess htaccess重定向参数不起作用

.htaccess htaccess重定向参数不起作用,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我正在为一个Apache重写规则而挣扎。我需要做以下工作: 永久重定向: 到 我得到了下面的代码,它在没有url参数的情况下工作,但我似乎无法让它与参数一起工作。我错过什么了吗 RewriteCond %{QUERY_STRING} ^prevent_cache=([0-9]*)$ RewriteRule ^/folder/viewer/data/settings.xml$ http://domain.com/siteid/includes/themes/siteid/swfs/viewer

我正在为一个Apache重写规则而挣扎。我需要做以下工作:

永久重定向:

我得到了下面的代码,它在没有url参数的情况下工作,但我似乎无法让它与参数一起工作。我错过什么了吗

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] 
干杯


肖恩,我能。以下是您要查找的重写条件和规则:

# 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]

但是请考虑一下关于[R=301]标志的回答:

我能看到的唯一错误是
重写规则
模式中的前导斜杠
/
。这应该是

RewriteCond %{QUERY_STRING} ^prevent_cache=[0-9]*$
RewriteRule ^folder/viewer/data/settings.xml$ /siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R,L]
您不需要将查询字符串附加到替换URL,因为这是自动完成的


当一切正常时,您可以将
R
更改为
R=301
。切勿在启用
301
的情况下进行测试,有关详细信息,请参阅此答案。

完美!谢谢你的帮助