htaccess to not show index.php in sub directory

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

I have a simple page structure like below

/directory/subdir_1/index.php

/directory/subdir_2/index.php

....

(there are no other files in these directories)

is it possible to have 'fake/pretty' urls for the above files as below?

/directory/subdir_1

/directory/subdir_2

...

so this path would show whether the visitor typed that,/directory/subdir_2/ or /directory/subdir_2/index.php.

Many thanks

回答1:

You could check $_SERVER['REQUEST_URI'] at the top of index.php to get the address and if the string ends with index.php redirect them. However, I would suggest not necessarily doing this and leaving it. Just change the links on your page to not include index.php.



回答2:

If you have

DirectoryIndex index.php 

in your .conf or .htaccess file, it should do that anyway. see http://httpd.apache.org/docs/2.2/mod/mod_dir.html#DirectoryIndex



回答3:

Question is too unclear to me.
but by default web-server works as you described:

Both /directory/subdir_2/ or /directory/subdir_2/index.php would run index.php from the /directory/subdir_2/.

If you want to redirect a client in case it requests /directory/subdir_2/index.php, to the /directory/subdir_2/ you'd better not to do it. Just have all links on your site without trailing index.php.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!