【问题标题】:Removing extensions from needing to be entered on a website删除需要在网站上输入的扩展名
【发布时间】:2015-05-18 03:26:22
【问题描述】:

我已经在这里阅读了大量关于此的主题和问题,我一生都无法弄清楚。

我正在努力做到这一点,所以当我访问我的网站时,我不必输入 .html 即可访问该页面 例如:www.yoursite.com/help 而不是 www.yoursite.com/help.html

我试过了:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule .* $0.html

在我的 .htaccess 文件中,它不起作用。

无论何时尝试在 url 中不包含 .html 时,您仍然会被重定向到我的错误页面

非常感谢任何帮助!

更新:.htacess

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

ErrorDocument 400 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 405 /error.php
ErrorDocument 408 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php

【问题讨论】:

  • 您能否用您的.htaccess 文件的全部内容更新您的问题?

标签: php html .htaccess


【解决方案1】:

试试这个:

ErrorDocument 400 /error.php 
ErrorDocument 403 /error.php 
ErrorDocument 404 /error.php 
ErrorDocument 405 /error.php 
ErrorDocument 408 /error.php 
ErrorDocument 500 /error.php 
ErrorDocument 502 /error.php 
ErrorDocument 504 /error.php

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ /%{REQUEST_URI}.html [L]

【讨论】:

    【解决方案2】:

    试试这个

    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    

    来源: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

    【讨论】:

    • 这不起作用。我尝试了该网页上的所有内容。 D:
    • 您的 apache 是否配置为使用 .htaccess?
    • 首先删除 .htacess 中的任何其他内容,然后按照该链接中的说明进行操作。
    • @udonsoup16 - 这不会有什么不同。如果设置为None,则根本不会加载OP 的.htaccess 文件。
    • @MikeAnthony 我也这么认为,但他说他有一个通过 .htacess 工作的重定向错误页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 2017-05-08
    • 1970-01-01
    相关资源
    最近更新 更多