Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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将/index.php?country=a重定向到/a/_Php_.htaccess_Url_Clean Urls - Fatal编程技术网

通过htaccess将/index.php?country=a重定向到/a/

通过htaccess将/index.php?country=a重定向到/a/,php,.htaccess,url,clean-urls,Php,.htaccess,Url,Clean Urls,重定向 www.example.com/index.php?country=a 到 尝试: RewriteCond %{QUERY_STRING} index.php?country=a [OR] RewriteCond %{REQUEST_URI} index.php?country=a RewriteRule ^ http://www.example.com/a/? [L,R=301] 不管用 注: 1) 如果a是动态的(我的列表中有60个国家),那么这个代码也是个坏主意 2) 要删除i

重定向

www.example.com/index.php?country=a

尝试:

RewriteCond %{QUERY_STRING} index.php?country=a [OR]
RewriteCond %{REQUEST_URI} index.php?country=a
RewriteRule ^ http://www.example.com/a/? [L,R=301]
不管用

注:

1) 如果
a
是动态的(我的列表中有60个国家),那么这个代码也是个坏主意


2) 要删除
index.php?country=a
之后的任何内容,例如:
index.php?country=a&p=d&xx=k

变量
%{QUERY\u STRING}
表示url的查询部分(后面的部分)

因此,您无法匹配模式中的uri
index.php
,请尝试:

RewriteCond %{QUERY_STRING} ^country=([^&]+)(?:&(.*))?$ [NC]
RewriteRule ^ http://www.example.com/%1/? [L,R=301]

在测试这些规则之前,请清除浏览器的缓存

RewriteRule ^/([a-zA-Z]+) index.php?country=$1 [NC,L]
它将帮助您从任何值获得一个干净的URL,而不仅仅是“a”

RewriteRule ^a$ index.php?country=a [NC,L]

这个肯定有用。。。确保index.php?country=a不在任何子目录中

是否要执行相反的重定向?为什么你要将“标准”url类型重定向到SEO类型?可能你错过了我的第二个注释。我不是在寻找干净的URL。正在尝试删除大量禁用的URL。您也可以在PHP应用程序中执行此操作。只需返回
标题('位置:http://example.com/country');那么有什么方法可以匹配'index.php'?请参阅第二个解决方案谢谢,但是您查看了有问题的注释吗a’是动态的here@smith是的,我做到了!是否要将表单/index.php的输入url重定向到/foo/?并在任何重写条件后忽略其他值?
RewriteRule ^/([a-zA-Z]+) index.php?country=$1 [NC,L]
RewriteRule ^a$ index.php?country=a [NC,L]