Forum Moderators: phranque
Now I want to redirect certain pages to the /old directory so the above URL would be: http://www.example.org/old/index.php?x=reviews&id=920
I only want to select reviews 200-920, this is currently what the .htaccess looks like:
RewriteCond %{QUERY_STRING} ^x=reviews&id=[200-920]?
RewriteRule ^index.php$ http://www.example.org/old/index.php [R=301]
this makes everything that has the "x=reviews&id=" string in it go to the /old/ directory not the pages with id's 200-920...any suggestions?
[edited by: jdMorgan at 4:53 pm (utc) on Oct. 30, 2009]
[edit reason] example.org. Please see TOS. [/edit]
This evaluates to "Match a single digit '2', '0', '0 through 9', '2', or '0', or totally blank." Then since the pattern is un-anchored, any characters which follow this sub-pattern are also matched by default.
Remember that regular-expressions work on characters and strings and do not "comprehend" numeric values at all; everything is treated as a character or a string of characters -- i.e. "symbols", and regex does not assign any "meaning" to the matched characters or strings.
I believe that what you want is more like:
RewriteCond %{QUERY_STRING} ^x=reviews&id=([1-9]?[0-9]¦[1-8][0-9][0-9]¦9[01][0-9]¦920)(&.*)?$
RewriteRule ^index.php$ http://www.example.org/old/index.php [R=301,L]
The rule, as is usually required and recommended, is terminated with an [L] flag.
Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Also, we generally recommend using "/" as the index page at any subdirectory level, assigning the index.whatever file as the index page filepath using the DirectoryIndex directive.
Having done that, we generally recommend linking and/or redirecting always to "/" and never to "index.whatever", as there is no need or advantage in 'exposing' your server-side technology to users and search engines, and doing so means that should you ever change that technology, you will have to redirect your index pages, suffering the attendant (usually temporary, but often long-lived) ranking loss as a result.
Jim
It also requires that you change all links on your site to point to those new URLs if you want good results in search.
So, if the filepath needs to change, but the URL does not, then I'd suggest using an internal rewrite instead of an external redirect; Leave the URLs as-is, and simply 'map' them to the new filepath using the same code, but with internal rewrite syntax -- i.e. change the RewriteRule line to
RewriteRule ^index.php$ /old/index.php [L] Jim
I would have used your 2nd suggestion except reviews920-1066 need to be directed to exact urls like this:
http://www.example.org/index.php?x=reviews&id=1065
needs to be:
http://www.example.org/new/seasonic-s12d-850w-power-supply-review/
[edited by: jdMorgan at 1:50 am (utc) on Oct. 31, 2009]
[edit reason] example.org [/edit]