Forum Moderators: phranque
RewriteRule http://www.example.com/?page_id=200 http://www.example.com/page-name/$1 [R=301,L]
On the first RewriteRule, (the Pattern) is matched against the (%-decoded) URL-path (or file-path, depending on the context) of the request. Subsequent patterns are matched against the output of the last matching RewriteRule.
RewriteRule ^/page-name-old/$1 http://www.example.com/page-name/$1 [R=301,L]
I just added [NC] at the end of the first line just in case.
RewriteRule ^/page-name-old/$1 http://www.example.com/page-name/$1 [R=301,L]
- When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the RewriteRule pattern matching and automatically added after any relative (not starting with a slash or protocol name) substitution encounters the end of a rule set. See the RewriteBase directive for more information regarding what prefix will be added back to relative substitutions.
- ...
- The removed prefix always ends with a slash, meaning the matching occurs against a string which never has a leading slash. Therefore, a Pattern with ^/ never matches in per-directory context.
WordPress seems to be based on a lot of stuff happening magically behind the scenes, so it can be used by people who know absolutely nothing. This is fine up until the moment you need to do something non-standard.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?page_id=200\ HTTP/
RewriteRule ^$ http://www.example.com/actual-page-name/? [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200\ HTTP/
RewriteRule ^(index\.php)?$ http://www.example.com/actual-page-name/? [R=301,L] Be aware of another limitation. If there are additional parameters requested, the request will not be redirected.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200\ HTTP/ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200&
RewriteRule ^(index\.php)?$ http://www.example.com/actual-page-name/? [R=301,L] Would adding an additional RewriteCond work for an additional parameter in URL?RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200\ HTTP/ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200&
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?page_id=200(?:&\S+)?\ HTTP/