这是我的网站。
http://matiny.tk/Antihero.html
正如您所看到的,.html
扩展名只是坐在最后。 .htaccess
对我不起作用。它导致CSS丢失,或者网站出现500内部错误。
我正在使用cPanel。
以下是无效的代码。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\ .html -f
RewriteRule ^(.*)$ $1 .html
下一个只是略有不同。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
我从Youtube上的某个人那里得到了这个......
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1 .html [L,QSA]
答案 0 :(得分:1)
有一个丑陋的解决方法:
将您的文件重命名为index.php
并将其放在名为Antihero
的文件夹中。
但最好是使用.htaccess
。你说你不能用它。向我们展示您的.htaccess
,我们会帮助您使用它!
修改在.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L,QSA]
答案 1 :(得分:1)
您想要的是所谓的漂亮网址。
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^Antihero$ ./Antihero.html
通过这种方式,您可以将您的链接分享为http://matiny.tk/Antihero,并且您的apache将保留该网址,而其下方实际上是在为Antihero.html提供服务。
请点击此处获取更多信息:http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
<强>编辑:强> 你的最后一个例子在我的htaccess文件中对我很好。 [已删除示例的链接(不再在服务器上使用.htaccess)]。如果它仍然无法正常工作,您是否可以验证是否已在apache中启用了htaccess支持?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html