.htaccess 文件无法在 linux 服务器上运行

.htaccess file not working on linux server

我知道还有更多关于此的问题和答案,但其中 none 对我很有用。

我刚刚在 apache linux 服务器上配置了我的网站,我正在使用 cPannel.And 进行管理 我编辑了我的 .htaccess 文件以从我的 html 中删除扩展名url。但是在我将它上传到文件管理器之后,changes.What 我不需要做任何事情来让它工作吗?

我一直在寻找配置文件来设置 AllowOverride All 但我没有找到 anything.And 而且我的文件管理器中没有 etc/apache2/ 目录,有etc/ 目录中的其他文件。

编辑:服务器信息:

主持Package:Startup2013

服务器名称:wolf

cPanel 版本:11.50.1(构建 3)

主题:paper_lantern

Apache 版本:2.4.16

PHP版本:5.6.12

MySQL版本:5.6.23

架构:x86_64

操作系统:linux

共享IP地址:185.81.0.40

Sendmail 路径:/usr/sbin/sendmail

Perl 路径:/usr/bin/perl

Perl 版本:5.10.1

内核版本:2.6.32-573.3.1.el6.x86_64

这是我的 .htaccess 代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .html [NC,L]

我假设您没有 运行 宁 ubuntu 服务器,这就是为什么您没有 /etc/apache2 目录。

试试这个:

编辑 /etc/httpd/conf/httpd.conf 中的 httpd.conf 文件并设置 AllowOverride All

然后:apachectl restart

如果这不起作用,请 运行: cat /etc/*-release 并向我们展示输出,以便我们知道您 运行 正在使用哪个 linux 发行版。

编辑: .htaccess 工作正常,OP 想删除 .html 扩展名

这是删除 .html 扩展名所需的 .htaccess:

RewriteEngine On
RewriteBase /

#Removes .html extension
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.html\sHTTP/.+
RewriteRule ^(.+)\.html  [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .html [NC,L]