admin管理员组

文章数量:1122826

I have a current site where all URLs end with .html.

I created a new site and the URLs are pretty much the same but without .html.

I've been trying codes found here in my .htaccess file and most seem to cause Internal Server Error.

.html to /
.html to /

My current .htaccess file code is:

# 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

I have a current site where all URLs end with .html.

I created a new site and the URLs are pretty much the same but without .html.

I've been trying codes found here in my .htaccess file and most seem to cause Internal Server Error.

http://example.com/page1.html to http://example.com/page1/
http://example.com/page1/page2.html to http://example.com/page1/page2/

My current .htaccess file code is:

# 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
Share Improve this question edited Sep 24, 2017 at 15:05 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Sep 24, 2017 at 13:16 AtashaAtasha 2431 gold badge3 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Just to note, when you get an Internal Server Error (code 500), you should check your server's error log for the specifics of the error. If you've been messing with mod_rewrite in .htaccess then this could be anything from a basic syntax error to a rewrite loop.

If you have no .html files on your new site then you can issue an unconditional redirect to remove the .html on the end of the URL. For example:

RewriteRule (.*)\.html$ /$1 [R=301,L]

This would need to go before the existing WordPress directives.

Or, if you do have some .html files that need to be served as-is then only redirect requests that do not map to an existing file. For example:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.html$ /$1 [R=301,L]

You will need to clear your browser cache before testing.

本文标签: htaccess301 Redirect all page and post urls from html to