Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i want to redirect pages from sitename/sitename/pagename.html and sitemap/sitename/ to

sitemap/sitename/pagename 

how i can do that by using .haccess file

i tried this code RewriteEngine On RewriteBase / RewriteRule . /sitename/index.php [L] RedirectMatch 301 (.*).html$ sitename/$1

and i tired also to add

 Redirect 301 sitename/sitename/

but it is not working but i think both not working because it still gives me an error when i open www.sitename.com/pagename.html

share|improve this question

1 Answer 1

%postname% is not a mod_rewrite rewrite tag. You are going to have to write out the path. mod_rewrite operates before WordPress, or PHP, gets involved. You don't have access to any of that functionality.

If your "contact" page-- the page named "contact"-- has ID 213 you shouldn't have to do anything to redirect, though. This will happen when you enable pretty permalinks.

You can also redirect using WordPress functionality by doing something like:

function redirect_213() {
  if (is_page(213)) {
    wp_safe_redirect(wp_safe_redirect(home_url('/contact')));
  }
}
add_action('template_redirect','redirect_213');

This will probably perform slightly less efficiently than the .htaccess but you may not notice.

share|improve this answer
    
thanks for reply but i want to do that not only for this page for all the other pages so i there is a way to do this for all pages -- i mean for all html pages –  sarah Mar 14 '13 at 14:24
    
That is very different from what you asked in your question. Please edit you question so that it actually asks what you want to ask! –  s_ha_dum Mar 14 '13 at 14:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.