无法重定向查询字符串 url [英] cannot redirect querystring url
问题描述
我正在尝试清理 url 重定向查询字符串 URL.我已经尝试了 stackoverflow 和其他站点中提供的所有答案和规则,但没有任何改变.我以为是 .htaccess 文件错误,但我发现它可以正常工作以生成其他错误.我正在尝试重定向
I am trying to clean url redirecting query string URL. I've tried all answer and rules provided in stackoverflow and in other sites, but nothing changed. I thought it was .htaccess file error, but I found it is working fine to generate other error. I am trying to redirect
http://localhost/ourallnews/category.php?cat=News
到
http://localhost/ourallnews/News/
首先我尝试使用它.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=(\w+)
RewriteRule ^ourallnews/category\.php$ /ourallnews/%1? [R=302,L]
之后我尝试了
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=(\w+)$
RewriteRule ^ourallnews.*$ /ourallnews/%1/? [R=302,L]
没有任何变化.
我清除了浏览器缓存,重新启动了 apache 但不起作用.查询字符串 url 保留.
I clear browser cache, restart apache but doesn't work. Querystring url is remained.
最后这个带来了变化.
RewriteCond %{QUERY_STRING} .
RewriteRule ^ %{REQUEST_URI}? [R=301,L]
变了
http://localhost/ourallnews/category.php?cat=News
到
http://localhost/ourallnews/category.php
但我的要求是显示查询字符串值而不是 URI.
But my requirement is show querystring value not URI.
http://localhost/ourallnews/news/
请帮帮我
推荐答案
你可以使用这个
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=(\w+)
RewriteRule ^ourallnews/category\.php$ /ourallnews/%1? [R=302,L]
这会将 /ourallnews/category.php?cat=value
重定向到 /ourallnews/value
.
This will redirect /ourallnews/category.php?cat=value
to /ourallnews/value
.
这篇关于无法重定向查询字符串 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!