2015-10-23 35 views
0

我的根文件夹中有两个文件:main.htmlindex.php。 那么,通常index.php发生的地方,因为它有更高的优先级响应,只是想改变逻辑,所以,首先用户必须访问main.html,然后重定向到index.php。我在我的.htaccess中尝试了下面的代码,但它不能如我所料。实际上,在这样做之后,现在第一页已正确更改为main.html,但它永远不会被重定向到index.php!它实际上返回main.html连连(如循环!).htaccess和DirectoryIndex

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

DirectoryIndex main.html /main.html 

PS:

1 - 即使我尝试请求的index.php它会打开main.html中,而不是!

回答

0

您可以在您的htaccess文件中使用以下内容更改目录的默认页面,就像您在问题中所做的那样。浏览“www.coolsite.com/”时,用户将登陆main.html(而不是index.php)。

//Change default directory page 
DirectoryIndex main.html 

将用户重定向到另一个页面,则可以使用以下命令:

window.location = "http://www.coolsite.com/index.php"; 
+0

感谢您的回复,所以我提到它是通过将DirectoryIndex添加到htaccess文件中完成的,但问题是该页面永远不会被重定向到index.php(我使用了相同的javascript)。它实际上又返回到main.html ...我想它与我在htaccess中使用的RewriteRules有关。请注意,我仍然需要该部分来处理网站中的固定链接。 – atari83

+0

只是一个小问题:这两个脚本的处理方式是否与Web服务器的处理方式不同:window.location =“http://www.coolsite.com/index.php”;和window.location =“index.php”; ?我问这个,因为现在我已经用第二个代码做了这个。 – atari83

+0

同样的问题,我想:http://serverfault.com/questions/469339/static-site-to-dynamic-rewrite-loop – atari83

0

好吧,看来WordPress和静态内容不会不来沿着[索引页!]! (主要是因为现有的RewriteRule [s] + WP内部)

解决方法是创建一个'页面模板'(您希望显示为索引页面的静态内容)并要求WP将其显示为前页。

相关问题