$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - redirect old pages by .htaccess|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - redirect old pages by .htaccess

matteradmin10PV0评论

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

sitemap/sitename/pagename 

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
</IfModule>

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/pagename.html

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

sitemap/sitename/pagename 

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
</IfModule>

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/pagename.html

Share Improve this question edited Feb 18, 2019 at 9:15 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Mar 14, 2013 at 13:43 sarahsarah 672 silver badges11 bronze badges 1
  • In trying to "exemplify" the code you've actually changed its meaning and made it invalid!? – MrWhite Commented Feb 17, 2019 at 22:18
Add a comment  | 

1 Answer 1

Reset to default 0

%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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far