我的.htaccess文件中有以下行:
DirectoryIndex index.html index.php
每次我去index.php,它都会把我带到index.html。有没有可能两者都允许,但让访问www.domain.com的用户保留index.html的默认设置?
发布于 2015-06-18 03:57:08
如果你使用的是WordPress,现在有一个过滤器钩子来解决这个问题:
remove_filter('template_redirect', 'redirect_canonical');
(将其放入主题的functions.php
中)
这告诉WordPress不要将index.php
重定向回根页面,而是原地踏步。这样,index.html
就可以被指定为.htaccess
中的默认页面,并且可以与index.php
一起使用。
发布于 2017-02-25 17:35:27
我同意@TheAlpha的公认答案,Apache从左到右读取DirectoryIndex目标文件,如果第一个文件存在,apche将为其提供服务,如果不存在,则下一个文件将作为目录的索引。因此,如果您有以下指令:
DirectoryIndex file1.html file2.html
Apache将提供/file.html作为索引,如果您想将/file2.html设置为索引,则需要更改文件的顺序
DirectoryIndex file2.html file1.html
您还可以使用RewriteRule设置索引文件
RewriteEngine on
RewriteRule ^$ /index.html [L]
上面的RewriteRule会将你的主页改写成/index.html。改写会在内部发生,所以http://example.com/会向你显示内容ofindex.html。
发布于 2012-04-10 19:51:16
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php%{QUERY_STRING} [L]
将这两行放在.htaccess文件的顶部。它将在.php页面的URL中显示.html。
RewriteEngine on
RewriteRule ^(.*)\.php$ $1.html%{QUERY_STRING} [L]
使用此选项在.html页面的URL中显示.php。
https://stackoverflow.com/questions/10002439
复制相似问题