【问题标题】:Relative Url in Subdirectory子目录中的相对 URL
【发布时间】:2019-02-06 19:59:34
【问题描述】:

我在domain.com 有一个站点,我想在blog 子目录中添加子站点。

在子目录的domain.com/blog/index.html 文件中,我尝试使用post-1/post-1./post-1 链接到单个帖子。

预期的 URL 是 domain.com/blog/post-1,但是链接上的 URL 是 domain.com/post-1

.htaccess 能否将子目录的 baseUrl 更新为domain.com/blog/?这意味着blog 目录中的所有relative url 都将是domain.com/blog/[some-url-here]

我试过了,但它不正确:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog/
  RewriteRule ^index\.html$ / [R=301,L]
  RewriteRule ^blog/(.*)/index\.html$ /$1/ [R=301,L]
</IfModule>

感谢您的帮助。

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting apache2 subdirectory


    【解决方案1】:

    您的替换(RewriteRule 的第二个参数)都以斜杠 ('/') 开头。这意味着该基地从未使用过。如果您希望合并 RewriteBase,请将它们设为相对。

    【讨论】:

    • RewriteRule 的第二个参数我去掉了一个斜线,还是不行。
    猜你喜欢
    • 2013-10-14
    • 2012-04-09
    • 2016-01-14
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 2018-04-24
    相关资源
    最近更新 更多