user3347198
user3347198

Reputation: 25

url Rewrite two urls in a folder

I want to rewrite Two URLs in a folder

first is

www.example.com/mybooks/list.php?id=novel-15 to www.example.com/mybooks/novel-15 for this i have the following code in mybooks/.htaccess file [.htaccess is in mybooks folder]

RewriteEngine on
RewriteBase /mybooks/ 

RewriteCond %{THE_REQUEST} /list\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ list.php?id=$1 [L,QSA]

Its working fine...

Now I want to rewrite

mybooks/search.php?search_word=mystery&search_option=all&page=4 to mybooks/mystery/all/4

i want to do this with out distrub the first rewrite option how can i do this

Upvotes: 1

Views: 44

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use:

RewriteEngine on
RewriteBase /mybooks/ 

RewriteCond %{THE_REQUEST} /search\.php\?search_word=([^\s&]+)&search_option=([^\s&]+)&page=([^\s&]+) [NC]
RewriteRule ^ %1/%2/%3? [R=302,L]

RewriteCond %{THE_REQUEST} /list\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/(\w+)/(\d+)/?$ search.php?search_word=$1&search_option=$2&page=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ list.php?id=$1 [L,QSA]

Upvotes: 1

Related Questions