Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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_Localhost - Fatal编程技术网

.htaccess htaccess-重定向条件在本地主机上不起作用

.htaccess htaccess-重定向条件在本地主机上不起作用,.htaccess,localhost,.htaccess,Localhost,我在htaccess中有这个重定向 我想重定向 http://localhost/www/foo/bar.php?city=new_york&data=4156 到 我已创建此htaccess: RewriteEngine on RewriteCond %{REQUEST_URI} bar\.php$ RewriteCond %{QUERY_STRING} ^city\=([^&]+)(.*)$ RewriteRule ^(.*)/bar.php$ http://%{HTT

我在htaccess中有这个重定向

我想重定向

http://localhost/www/foo/bar.php?city=new_york&data=4156

我已创建此htaccess:

RewriteEngine on

RewriteCond %{REQUEST_URI}  bar\.php$
RewriteCond %{QUERY_STRING} ^city\=([^&]+)(.*)$
RewriteRule ^(.*)/bar.php$ http://%{HTTP_HOST}/$1/%1/?%2 [L,R=301]

但这在本地主机上不起作用。URL保持不变,旧的。我已经测试了这些规则,它们似乎按照预期工作。那么这只是本地主机的问题还是htaccess错误?

您可以在
foo/.htaccess
中使用此规则:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^city=([^&]+)&(.*)$ [NC]
RewriteRule ^bar\.php$ /foo/%1/?%2 [L,R=301]

请注意,这将重定向到
http://localhost/www/foo/new_york/?data=4156
因为在URL中的
后面没有一个
&

RewriteCond%{QUERY_STRING}(?:^ |和)city=([^&]+)(?:&|$)
你的.htaccess在哪里?它在
/foo/
目录中吗?@anubhava是的,它在/foo/目录中
RewriteEngine on

RewriteCond %{QUERY_STRING} ^city=([^&]+)&(.*)$ [NC]
RewriteRule ^bar\.php$ /foo/%1/?%2 [L,R=301]