URL RewriteCond用于动态网址

时间:2014-01-09 14:45:14

标签: .htaccess url mod-rewrite rewrite

这是我的动态网址

http://www.125books.com/search-bk?s=20&kw=thermodynamics&ser=y

我希望它在最后重写这个url和kw参数,这样它可能看起来像这样

http://www.125books.com/search-bk/20/y/thermodynamics

请帮助我如何在.htaccess文件中设置RewriteCond以及如何设置重写规则

1 个答案:

答案 0 :(得分:0)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(search-bk(?:\.php)?)\?s=([^&]*)&kw=([^&]*)&ser=([^\s&]*) [NC]
RewriteRule ^ /%1/%2/%4/%3? [R=302,L,NE]

RewriteRule ^(search-bk)/([^/]+)/([^/]+)/([^/]+)/?$ /$1?s=$2&kw=$4&ser=$3 [L,QSA]

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]