【问题标题】:How can I make my site load example.html when somebody visits example.com/example当有人访问 example.com/example 时,如何让我的网站加载 example.html
【发布时间】:2019-05-22 22:02:02
【问题描述】:

我的public_html 文件夹中有一个名为example.html 的文件。

当有人访问example.com/example.html 时,他们会收到 404 响应。

我怎样才能让 Apache 服务 example.html

我有一堆这样的文件,所以我更愿意创建某种通用规则,而不是单独重定向它们。

【问题讨论】:

    标签: apache .htaccess redirect path http-status-code-404


    【解决方案1】:
    #Turning RewriteEngine On
    RewriteEngine on
    
    #Making sure a directory or file does not exist under that name
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    #RewriteRule {WHAT THE USER SEES} {WHAT IS CALLED}
    RewriteRule ^example$ example.html
    

    这样,加载example.com/example 将显示example.html 加载的任何内容。

    如果您有一堆要以该格式加载的 HTML 文件,请使用:

    RewriteRule ^(.*)$ $1.html
    

    你可以在第一个参数中加入任何你想要的正则表达式。

    【讨论】:

    • 谢谢,成功了! cmets 也很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    相关资源
    最近更新 更多