简体   繁体   English

htaccess不在子目录中显示index.php

[英]htaccess to not show index.php in sub directory

I have a simple page structure like below 我有一个简单的页面结构,如下所示

/directory/subdir_1/index.php /directory/subdir_1/index.php

/directory/subdir_2/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? 上面的文件是否可能具有“假/漂亮” URL,如下所示?

/directory/subdir_1 / directory / subdir_1

/directory/subdir_2 / directory / subdir_2

... ...

so this path would show whether the visitor typed that,/directory/subdir_2/ or /directory/subdir_2/index.php. 因此此路径将显示访问者键入的是/ directory / subdir_2 /还是/directory/subdir_2/index.php。

Many thanks 非常感谢

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. 您可以检查index.php顶部的$_SERVER['REQUEST_URI']以获取地址,以及字符串是否以index.php结尾将其重定向。 However, I would suggest not necessarily doing this and leaving it. 但是,我建议不必这样做并保留它。 Just change the links on your page to not include index.php. 只需更改页面上的链接即可不包含index.php。

If you have 如果你有

DirectoryIndex index.php

in your .conf or .htaccess file, it should do that anyway. 在您的.conf或.htaccess文件中,无论如何应该这样做。 see http://httpd.apache.org/docs/2.2/mod/mod_dir.html#DirectoryIndex 参见http://httpd.apache.org/docs/2.2/mod/mod_dir.html#DirectoryIndex

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/ . 无论/directory/subdir_2//directory/subdir_2/index.php将运行在index.php文件/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. 如果你想重定向客户端的情况下,它要求/directory/subdir_2/index.php ,到/directory/subdir_2/你最好不要去做。 Just have all links on your site without trailing index.php. 只需在您的站点上拥有所有链接,而无需尾随index.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM