2013-10-18 62 views
1

在我.htaccess文件DirectoryIndex设置为/page/main/home.html的.htaccess DirectoryIndex的网页链接打破

因此,当我去www.thisexample.com浏览器的地址栏中显示www.thisexample.com而实际加载www.thisexample.com/page/main/home.html。这一切都很好,但现在解决了这个问题:

任何.html无法找到链接到home.html的页面。换句话说,当我点击信息链接(在主页上)时,它会查找www.thisexample.com/info.html(不存在),而不是在浏览器地址栏中显示www.thisexample.com/info.html,但实际上正在加载www.thisexample.com/page/main/info.html(此处为最终目标)。

这可能有助于补充说home.html没有问题通过相对路径找到它的CSS样式表,只是找不到链接。

回答

0

DirectoryIndex应该是默认文件名像index.htmlindex.php为前名:

DirectoryIndex index.html 

如果你想从/page/main加载所有的.html文件,然后有这些重写规则:

DirectoryIndex home.html 

RewriteEngine On 

RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC] 
RewriteRule !^page/main/ page/main%{REQUEST_URI} [L,NC] 

也开始在你的CSS,JS,图像文件,而不是相对的使用绝对路径。这意味着您必须确保这些文件的路径始于http://或斜杠/

+0

我在'/ public_html'的'.htaccess'文件中添加了'RewriteRule!^ page/main// page/main%{REQUEST_URI} [L]'。我仍然有'DirectoryIndex/page/main/home.html',否则它只是把我带到父目录。链接仍然不起作用。你能澄清实施吗? – user1345660

+0

如果您发现css,js,图片链接被破坏,请在您的HTML页面上尝试''。 – anubhava

+0

你只需要'DirectoryIndex home.html' – anubhava