将查询重定向到文件夹

时间:2012-12-24 13:36:30

标签: .htaccess mod-rewrite redirect

我的网址是:

http://site.com/consulting/search.php?searchterm59

并希望将其处理为search.php,但网址应该是这样的:

http://site.com/consulting/search/searchterm59

我也试过这个:

我试过这个

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/constulting/search\.php$
RewriteCond %{QUERY_STRING} ^([0-9]*)$
RewriteRule ^(.*)$ http://site.com/consulting/search/%1 [R=302,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ search.php$1 [L,QSA]
RewriteRule ^/?$ search.php?%1 [L,QSA]

2 个答案:

答案 0 :(得分:1)

也许这就是你要找的东西:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  /(.*)/search.*
RewriteRule .*        %1/%{QUERY_STRING}?     [L,R=301]

答案 1 :(得分:1)

$DOCUMENT_ROOT/.htaccess代码替换为:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

# for external redirect to /consulting/search/searchterm59
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(constulting/search)\.php\?([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

# for internal forward to /consulting/search.php?searchterm59
RewriteRule ^(constulting/search)/(.*)$ /$1.php?$2 [L,QSA,NC]