我试图将所有用户的请求redirect到我的索引页面,除了根目录文件夹。
所以www.domain.com/page.ext是好的,而www.domain.com/folder/page.ext必须redirect。
这是我的.htaccess:
RewriteEngine on RewriteRule ^([^/]+)/?$ /index.html [L] ErrorDocument 404 /index.html
它导致Internal Server Error ,我不知道为什么。
基本上我想强制用户在任何情况下都只访问index.html页面。
build议?
编辑:
只是为了给更多的信息,这是我的网站结构:
/ |-- index.html |-- css |-- site.css |-- js |-- site.js |-- images |-- img1.png |-- img2.png |-- img3.png
正如你所看到的,它非常简单。
我需要做的是始终显示我的index.html (它使用css/site.css , js/site.js和图像在CSS中使用)
所以用户请求的页面不重要,我的站点必须显示索引一。 这意味着,即使在404错误的情况下,即使用户请求不存在的文件夹中的页面,也必须显示索引!
在一个.htaccess文件中,匹配string(你在正则expression式中没有,没有前导斜杠)和replacestring都使用相对path(或RewriteBase ,如果configuration了RewriteBase话)。
试试RewriteRule ^([^/]+)/?$ index.html [L]
编辑:
为了避免在image / js / css文件中这样做,可以使用RewriteCond来防止应用规则:
RewriteCond %{REQUEST_URI} !^/images [NC] RewriteCond %{REQUEST_URI} !^/css [NC] RewriteCond %{REQUEST_URI} !^/js [NC] RewriteRule ^([^/]+)/?$ index.html [L]