1

我有以下网址:

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

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

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]
4

2 回答 2

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]
于 2012-12-24T15:26:45.040 回答
1

也许这就是你正在寻找的:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  /(.*)/search.*
RewriteRule .*        %1/%{QUERY_STRING}?     [L,R=301]
于 2012-12-24T14:36:56.260 回答