如何更改子文件夹中的多个参数

How to change multiple parameters in subfolder

如果查询字符串有多个参数,如何重定向和更改子文件夹中的最后一个。如果只有一个参数删除子文件夹?我只能重定向一个,但是当我尝试两个参数时,它变得一团糟。

localhost/mynews/category.php?cat=news
localhost/mynews/category.php?cat=news&subcat=9

localhost/mynews/news
localhost/mynews/news/9

如果你想这样做,在 .htaccess 中你可以做下一个:

Rewriterule ^mynews/(.+)/(.+)$ category.php?cat=&subcat=

其中 (.+) 表示 $ 之后的每个值。

您可以在 mynews/.htaccess 中使用此代码:

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=&subcat= [L,QSA,NC]

RewriteRule ^([\w-]+)/?$ category.php?cat= [L,QSA,NC]