如果querystring有多个参数,如何重定向和更改子文件夹中的最后一个。如果只有一个参数删除子文件夹?我只能重定向一个,但是当我尝试两个参数时,它会变得混乱。
localhost/mynews/category.php?cat=news
localhost/mynews/category.php?cat=news&subcat=9
要
localhost/mynews/news
localhost/mynews/news/9
答案 0 :(得分:1)
您可以在Options +FollowSymLinks
RewriteEngine On
RewriteBase /mynews/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /category\.php\?cat=([\w-]+)&subcat=([\w-]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteCond %{THE_REQUEST} /category\.php\?cat=([\w-]+)\s [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^([\w-]+)/([\w-]+)/?$ category.php?cat=$1&subcat=$2 [L,QSA,NC]
RewriteRule ^([\w-]+)/?$ category.php?cat=$1 [L,QSA,NC]
:
@Inject @Conf("key.in.properties.file")
protected String value;
答案 1 :(得分:0)
如果你想这样做,你可以在.htaccess中进行下一步:
Rewriterule ^mynews/(.+)/(.+)$ category.php?cat=$1&subcat=$2
(.+)
表示$
之后的每个值。