简体   繁体   English

.htaccess重写,尝试除去索引文件以外的所有文件上的.html文件扩展名

[英].htaccess rewrite, trying to remove .html file extension on all files EXCEPT index file

I'm trying to do a "simple" rewrite for all of my files so that you don't have to go to a link with .html at the end of the url. 我正在尝试对我的所有文件进行“简单”重写,以使您不必转到URL末尾带有.html的链接。 I've got a code that works almost completely, except for the fact that it's rewriting ALL of the files, which then screws up my index.html file and that's kind of a big problem. 我有一个几乎可以完全正常工作的代码,除了它正在重写所有文件,然后将我的index.html文件搞砸了,这是一个大问题。 This is the code that I'm using: 这是我正在使用的代码:

Options FollowSymLinks
DirectorySlash Off
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html

I guess I just need a code in there that makes it ignore index.html, so I tried this, which gave me error 403 on my index page and error 500s on every other page: 我想我只需要一个代码即可忽略index.html,所以我尝试了一下,这使我的索引页面上出现了错误403,其他页面上出现了500s:

RewriteRule ^index.html$ $0 [L]

But I guess in the end, I'm not entirely sure what I'm doing and I don't know where to put the line of code, and I don't know if it's even entirely correct. 但是最后我想我不确定自己在做什么,也不知道在哪里放置代码行,也不知道它是否完全正确。

The ORIGINAL code that I tried was this but that gave me error 403s on every page: 我尝试过的原始代码是这样,但是在每个页面上都给我错误403s:

Options FollowSymLinks
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html

What am I doing wrong? 我究竟做错了什么?

Try this code: 试试这个代码:

Options FollowSymLinks
RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1.html -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f [OR]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^((?!index).+?)/?$ $1.html [L,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM