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


how I can do that by using .htaccess file

I tried this code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule . /sitename/index.php [L]
RedirectMatch 301 (.*)\.html$ sitename/$1

and I tried 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

  • In trying to "exemplify" the code you've actually changed its meaning and made it invalid!?
    – MrWhite
    Commented Feb 17, 2019 at 22:18

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)) {

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

  • 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
    Commented Mar 14, 2013 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
    Commented Mar 14, 2013 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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