子目录中的相对URL

时间:2016-07-04 15:14:50

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

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

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

预期的网址 domain.com/blog/post-1 但是,该链接上的网址为domain.com/post-1

.htaccess可以将子目录的baseUrl更新为domain.com/blog/吗?这意味着blog目录中的所有相对网址都将为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>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的替换(RewriteRule的第二个参数)都以斜杠开头(&#39; /&#39;)。这意味着永远不会使用基地。如果你想要整合RewriteBase,请使它们相对。

相关问题