简体   繁体   中英

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

Can anyone help me with .htaccess rewrite url, I am new to it and stuck with this below problem

i have this urls

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

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

and i want this to be

http://example.com/catelogue

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

Below is my .htaccess file, but here the problem is I have achieved this (example.com/catelogue/fruit/apple) but I can't redirect my url to (example.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=$1&cat2=$2 [NC,L]

This should work. Try your rules this way. It works for me.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM