Forum Moderators: phranque
http://example.com/index.php?itemid=N RewriteEngine on
# Catch example items and redirect to new URL
RewriteCond %{QUERY_STRING} ^itemid=123$
RewriteRule ^itemid=[0-9]+$ http://example.com/new-blog-item-URL/ [R=301,L]
# Catch all other old items and redirect to specific new URL
RewriteCond %{QUERY_STRING} ^itemid=[0-9]+$
RewriteRule ^itemid=[0-9]+$ http://example.com/specific-new-page-URL/ [R=301,L]
# BEGIN jdMorgan's WordPress rewrite
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END wordpress
# Strip "www" from the URL
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] example.com[b]/[/b]itemid=222[b]?[/b]itemid=222 which will fail to match your actual requests.
RewriteEngine on
# Strip "www" from the URL
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
# BEGIN jdMorgan's WordPress rewrite
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END wordpress
RewriteCond %{QUERY_STRING} ^index\.php\?itemid=554
RewriteRule ^index\.php\?itemid=554 http://example.com/new-blog-item-URL/? [R=301,L]
RewriteCond %{QUERY_STRING} ^itemid=[0-9]+$
RewriteRule ^itemid=[0-9]+$ http://example.com/specific-new-page-URL/? [R=301,L]
http://example.com/index.php?itemid=554
GET /index.php?itemid=554 HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
HTTP/1.1 301 Moved Permanently
Date: Tue, 27 Apr 2010 13:08:36 GMT
Server: Apache
X-Pingback: http://example.com/wordpress/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Tue, 27 Apr 2010 13:08:36 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Location: http://example.com/?itemid=554
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Via: 1.1 vhost.phx4.nearlyfreespeech.net:3128 (squid/2.7.STABLE7)
----------------------------------------------------------
http://example.com/?itemid=554
GET /?itemid=554 HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
HTTP/1.1 200 OK
Date: Tue, 27 Apr 2010 13:08:36 GMT
Server: Apache
X-Pingback: http://example.com/wordpress/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Tue, 27 Apr 2010 13:08:36 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Via: 1.1 vhost.phx4.nearlyfreespeech.net:3128 (squid/2.7.STABLE7)
----------------------------------------------------------
domainname/path-part?query-string and you need to test parts of that. QUERY_STRING RewriteCond pattern can see ONLY the "query string" data. RewriteRule pattern can see ONLY the "path part" of the URL request.
path-part?query-string ?
RewriteEngine on
RewriteRule ^index\.php\?itemid=554 http://example.com/new-blog-item-URL/? [R=301,L]
RewriteCond %{THE_REQUEST} ^itemid=[0-9]+$
RewriteRule ^(.*)$ http://example.com/new-specific-page-URL/? [R=301,L]
# Strip "www" from the URL
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
# BEGIN jdMorgan's WordPress rewrite
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END wordpress
RewriteEngine on
RewriteCond %{QUERY_STRING} &?[b]itemid=554[/b]&? [NC]
RewriteRule [b]^(index\.php)?$[/b] http://example.com/new-blog-item-URL/? [R=301,L]
RewriteCond %{QUERY_STRING} &?[b]itemid=[0-9]+[/b]&? [NC]
RewriteRule [b]^(index\.php)?$[/b] http://example.com/specific-new-page-URL/? [R=301,L]
# Strip "www" from the URL
RewriteCond %{HTTP_HOST} [b]!^(example\.com)?$[/b]
RewriteRule (.*) http://example.com/$1 [R=301,L]
# BEGIN jdMorgan's WordPress rewrite
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END wordpress