url重写文件夹中的两个URL

时间:2014-11-20 18:59:19

标签: apache .htaccess mod-rewrite redirect url-rewriting

我想重写文件夹中的两个网址

首先是

www.example.com/mybooks/list.php?id=novel-15www.example.com/mybooks/novel-15为此我在mybooks / .htaccess文件中有以下代码[.htaccess在mybooks文件夹中]

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]

工作正常......

现在我要重写

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

我想通过distrub第一次重写选项来完成这个,我该怎么做

1 个答案:

答案 0 :(得分:1)

您可以使用:

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]