好的,所以我的网站有这样的动态网址
web.com/?city=London我想将其更改为
web.com/London当我发现重写代码时,我很难找到一个改变的代码,并立即将人们重定向到那种格式的URL。
答案 0 :(得分:0)
嗯,你可以这样做:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} (?:(.*)&)city=([^&]+)(.*)
RewriteRule ^(index.php)?$ %2?%1%3 [R,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(js|css|jpe?g?|png|gif)$
RewriteCond %{REQUEST_URI} !^index.php
RewriteRule ([^/]+) index.php?city=$1 [L,QSA]
index.php?city=London
,然后通过子请求提供新创建的请求(隐藏浏览器中的真实URL)。但是,请注意,这会导致浏览器不必要的重定向,因此您应该考虑重新构建服务器端应用程序中的URL,而不是严重依赖于此方案的第1部分,因此它们将出现在“正确”中“形式开始。