我想重写
mypage.com/country/country.php?country=something
到
mypage.com/country/something
在地址栏中,使用htaccess
我尝试过很多东西,到处寻找,最接近的是:
RewriteCond %{QUERY_STRING} country=([^\&]*)
RewriteRule ^country.php$ /country/%1? [R,L]
但这只会产生一个重写循环,在上面的两个链接之间交替,我不明白为什么。
我想要两个
mypage.com/country.php?country=something
和
mypage.com/country/something
输入时,显示
mypage.com/country/something
地址栏中的
任何帮助?
答案 0 :(得分:0)
如果你有一个重写循环,它表明除了该规则,你还有一个规则可以将其翻译回来。你需要丑陋的' url仅在外部请求时触发。最简单的方法是匹配%{THE_REQUEST}
。
#Ugly to fancy url; should be R=301 when it works
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /country\.php\?country=([^\&]*)\ HTTP
RewriteRule ^country.php$ /country/%2? [R,L]
RewriteRule ^country/(.*)/?$ /country.php?country=$1 [L]