2012-11-02 171 views
2

我有以下url我想用Mod Rewrite在根中使用.htaccess文件進行重定向。我已經搜索並找到索引文件在根目錄下的很好的例子,但不是在子文件夾中。 這就是我所擁有的和我需要的東西。 非常感謝您的幫助。將子文件夾index.php重定向到子文件夾根

/folder1/index.php /folder1/index.php/ 到 http://www.example.com/folder1/

/folder2/index.php /folder2/index.php/ 到 http://www.example.com/folder2/

我只要求2個超鏈接,所以我刪除了上面例子中的部分鏈接。我喜歡更短的方式,因爲我有很多文件夾。

+0

我想要:http://www.example.com/folder1/index.php http://www.example.com/folder1/index.php/至http://www.example.com/folder1/ –

+0

我不確定你的問題是否有意義。你想運行folder1/index.php,但只顯示folder1 /? – Codeguy007

+0

這很奇怪......我試圖用換行符進行格式化,這是不可能的。我想要: –

回答

0

在你的.htaccess文件中試試這個。

RewriteEngine On 

Rewrite ^/folder1/index.php$ /folder1/ [L] 
<Directory folder1> 
    DirectoryIndex index.php 
</Directory> 

當然,索引可以是你想要的每一個像newindex.php。

+0

對不起,這段代碼不起作用。我測試並改變了confg,沒有運氣。 –

+0

有人可以幫我解決這個問題嗎?謝謝! –

0

要/folder/index.php重定向到/文件夾,您可以使用:

RewriteEngine on 


RewriteRule ^([^/]+)/index\.php$ /$1/ [NC,L,R] 

這將重定向:

  • /anyfolder/index.php

  • /anyfolder/
相關問題