1

I need to update my .htaccess file to redirect permanently all URLs from http://example.com/pages/5604/article/something/?page=299 to http://example.com/pages/5604/article/. Here is my implementation (which sadly doesn't work):

RewriteRule ^pages/(.*)/(.*)/something/\?page=(.*) /pages/$1/$2 [R=301,L]

Thanks in advance for your help and suggestions!

4

1 に答える 1

2

The QUERY_STRING is not in the url that is matched, you'll have to match that separately in a RewriteCond. Something like (untested):

RewriteCond %{QUERY_STRING} ^page=(.*) 
# Apache >=  2.4
RewriteRule ^pages/(.*)/(.*)/something/ /pages/$1/$2 [R=301,L,QSD]
# Apache <  2.4 
RewriteRule ^pages/(.*)/(.*)/something/ /pages/$1/$2? [R=301,L]

If you need the value after page= in your RewriteRule, you can use %1 in the same way you use $1 (matches in RewriteCond's are %N, in RewriteRule $N)

于 2012-06-19T18:33:51.223 に答える