【问题标题】:htaccess URL Rewrite - Root to Subfolder (with folder of the same name)htaccess URL 重写 - 根到子文件夹(具有相同名称的文件夹)
【发布时间】:2015-06-11 23:50:25
【问题描述】:

我在 www.domain.com/blog/blog.html 有一个文件,我想将其重写为 www.domain.com/blog。

我已经找到了删除扩展名 .html 的重写,但是在尝试执行上述操作时遇到循环问题或最终将博客重写指向博客文件夹。

我是重写语法的新手,非常感谢您的帮助!

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    如果 /blog/.htaccess 尚不存在,则创建它并放置此规则:

    RewriteEngine On
    RewriteBase /blog/
    
    RewriteRule ^/?$ blog.html [L]
    
    # To internally forward /blog/file to /blog/file.html
    RewriteCond %{DOCUMENT_ROOT}/blog/$1\.html -f [NC]
    RewriteRule ^(.+?)/?$ $1.html [L]
    

    【讨论】:

    • 这现在给了我:www.domain.com/blog/ - 如何删除尾部斜杠?另外,现在我无法访问子文件夹中的页面,即 www.domain.com/blog/1506。
    • 否,但我有一个重写规则,删除根文件夹 .htaccess 中所有文件的 .html 扩展名。
    • 是的,我有一个目录 /blog/ ,其中有 html 文件 blog.html 和其他文件,例如 1506.html、1505.html 等。
    • 这对其他文件有效(谢谢!)但 www.domain.com/blog/blog.html 仍然重写为 www.domain.com/blog/ - 如何删除尾部斜杠?
    • 太棒了,这是有道理的,我想我可以接受这种观点,因为请求 www.domain.com/blog 仍然会将我带到该页面。感谢您的所有帮助,非常棒!
    猜你喜欢
    • 2021-11-20
    • 2014-03-20
    • 2020-01-09
    • 1970-01-01
    • 2012-05-17
    • 2021-11-02
    • 1970-01-01
    • 2015-10-06
    • 2020-01-08
    相关资源
    最近更新 更多