单页网站.htaccess

时间:2013-08-01 15:53:59

标签: .htaccess redirect rewrite subdirectory url-redirection

让我们看看我是否能够很好地解释这种情况。我有一个单页网站,所有内容都在屏幕上,但是隐藏了。如果,peg,你去 domain.com/product/about 我会把第一部分转到div-column“product”和div-row“about”,和some Javascript和CSS定位

问题:我需要我的.htaccess将所有网址(index.html ofc除外)重写为index.html(或我们设置的任何网址)。

问题中的问题:此网页位于子目录中,它可能 - 可能 - 位于第二级子目录中(即(root)/ folder / subfolder / thisweb 的)。让我们看看最后一个案例,所以它会更容易上升而不是下来。

我有什么:

RewriteEngine on
Options +FollowSymLinks
RewriteBase /folder/subfolder/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !^index.html
RewriteRule .* /index.html [L]

会发生什么:

  • domain.com/subfolder/foo:重定向到domain.com/folder/subfolder /
  • domain.com/subfolder/foo/:在此服务器上找不到请求的网址/ er1csports / test / foo /。

使用其他规则,有时我被重定向到父文件夹index.html。就像RewriteRule根本没用 - JFYI

我需要什么:

  • 正如我所说的那样,重写一下index.html,而不更改地址栏中的URL - 这应该与URL的子级别无关( foo / foo2 / foo3 < / i>还应该重写为index.html)。
  • 图像,CSS,Javascript,一般资源,如果它们的URL和引用不受影响,那就太棒了。
  • 无论URL是什么,“文件夹”都不应出现在URL地址栏中。 如果我被告知如何隐藏“子文件夹”,如果在两种情况下应用的规则都不同,那么也会很棒

我知道很多事情。但是我讨厌.htaccess而且我一直在寻找和搞乱几个小时,我一直无法找到它。

我将继续搜索和尝试,但我不想要的是在有一种方法只写10并保持干净时写100行。

非常感谢您的帮助和时间!

1 个答案:

答案 0 :(得分:0)

尝试在.htaccess中使用此代码:

Options +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /folder/subfolder/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule . index.html [L]