【问题标题】:htaccess two commands in the same filehtaccess 在同一个文件中的两个命令
【发布时间】:2014-04-26 03:25:10
【问题描述】:

嗨,我有我的 htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.htm [L]

ErrorDocument 404 /404.htm

如果我删除前 4 行,另一段代码(当找不到页面时重定向 de 404 页面)不再起作用。

有什么想法吗? 我还希望当它重定向到 404.htm 时,它不会显示在 url 框中,这个 url

http://www.mypage.com/404.htm

我想展示这个

http://www.mypage.com/fail/search-by-the-user

例如。

【问题讨论】:

    标签: php html .htaccess


    【解决方案1】:

    尝试关注 .htaccess

    RewriteBase /
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ /$1.html
    
    ErrorDocument 404 /404.html
    

    注意:如果您在 localhost 工作,请提及正确的 RewriteBase

    【讨论】:

    • 第一个问题解决了,你知道第二个问题的解决方案吗?
    • @Nick,没有遇到第二个问题,请说明清楚
    • 如果您访问:google.com/dhfjsdfsdjfsd 错误加载到该页面,它不会重定向到名为“404”或“未找到”的页面。但在我的页面中,它重定向到“404.htm”,我不希望看到它
    • @Nick,这项工作与最后在 .htaccess 中提到的 ErrorDocument 一起工作。它不重定向,只输出 404 文档
    • @Nick,不要在 .htaccess 中使用完整路径,在 404.htm 中使用 CSS 文件的完整路径
    猜你喜欢
    • 2017-02-03
    • 2014-02-08
    • 2013-05-23
    • 1970-01-01
    • 2015-01-04
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多