$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'); ?>url rewriting - 301 Redirect all posts urls from .html to(without .html)|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)

url rewriting - 301 Redirect all posts urls from .html to(without .html)

matteradmin9PV0评论

How can i redirect all posts permalinks from .html to / ,in Wordpress ? now all my posts url are ending in / ,but before it was with .html

to be more clear ,for example a post url like this /%category%/%postname%.html to be redirected to /%year%/%monthnum%/%postname%/ . It's simple to redirect them one by one,but i need a rule to redirect all posts .

my curent .htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

======

Thank you

How can i redirect all posts permalinks from .html to / ,in Wordpress ? now all my posts url are ending in / ,but before it was with .html

to be more clear ,for example a post url like this http://sitename/%category%/%postname%.html to be redirected to http://sitename/%year%/%monthnum%/%postname%/ . It's simple to redirect them one by one,but i need a rule to redirect all posts .

my curent .htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

======

Thank you

Share Improve this question edited Sep 14, 2011 at 14:18 Elliott 5426 silver badges15 bronze badges asked Sep 14, 2011 at 13:31 rigorigo 11 silver badge1 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 4

it's curious that redirect_canonical doesn't work in this case, but this will redirect everything with .html via .htaccess:

RewriteRule (.+)\.html?$ http://example/$1/ [R=301,L]

but keep in mind this will redirect everything with .html, you may need to explicitly exclude things.

That's strange. I thought WordPress did that automatically. Here's the default one that WordPress generated for me:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Try that on for size. Note how this one includes <IfModule mod_rewrite.c> and </IfModule>

Post a comment

comment list (0)

  1. No comments so far