如何使用 .htaccess 重写 example.com/catelogue.php?page=3&cat1=fruit&cat2=apple

How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess

任何人都可以帮助我重写 .htaccess url,我是新手并且遇到了以下问题

我有这个 urls

http://example.com/catelogue.php?page=3

http://example.com/catelogue.php?page=3&cat1=fruit&cat2=apple

我希望这样

http://example.com/catelogue

http://example.com/catelogue/fruit/apple

下面是我的 .htaccess 文件,但这里的问题是我已经实现了这个(示例。com/catelogue/fruit/apple)但是我无法将我的 url 重定向到(示例。com/catelogue).

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^home index.php?page=1 [NC,L]

RewriteRule ^catelogue catelogue.php?page=3 [NC,L]

RewriteRule ^catelogue/([^/.]+)/([^/.]+)$ catelogue.php?page=3&cat1=&cat2= [NC,L]

这应该有效。以这种方式尝试你的规则。这个对我有用。

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^catelogue/([^/]+)/([^/]+)$ catelogue.php?page=3&cat1=&cat2= [NC,L]
RewriteRule ^catelogue/?$ catelogue.php?page=3 [NC,L]
RewriteRule ^home/?$ index.php?page=1 [NC,L]