使用htaccess或PHP或任何东西重定向访问者 [英] Redirecting visitor using htaccess or PHP or anything

查看:69
本文介绍了使用htaccess或PHP或任何东西重定向访问者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

is there anyway to direct a visitor using htaccess or anything else from directories like this

http://domain.com/afolder/bfolder/index.php to http://domain.com/afolder/bfolder/

i want it like that when visitor goes to first directory he must be redirected to second one. the point is to hide this part "index.php"





我尝试过:





What I have tried:

i have tried this on htaccess file for testing only but it goes wrong

Redirect 302 /afolder/bfolder/index.php /afolder/bfolder/

推荐答案

首先,您必须了解Web服务器在请求目录而不是特定目录时所执行的操作页。大多数服务器将查看目录是否包含特定文件,并将返回存在的第一个文件。如果没有这些文件,可能会生成目录列表(如果已启用)或返回错误消息(不允许目录列表)。



使用Apache这个配置了 mod_dir - directoryindex [ ^ ]选项。



要启用目录列表,请使用 mod_autoindex - Apache HTTP Server版本2.4 [ ^ ]选项并设置选项+索引(例如在htaccess文件中)。



mod_alias - redirect [ ^ ]您尝试过无法处理文件:

At first you have to understand what a web server is doing when requesting a directory instead of a specific page. Most servers will look if the directory contains specific files and will return the first that exists. If there is none of these files, a directory listing might be generated (if enabled) or an error message is returned (directory listings not allowed).

With Apache this is configured with the mod_dir - directoryindex[^] option.

To enable directory listings use the mod_autoindex - Apache HTTP Server Version 2.4[^] option and set Options +Indexes (e.g. in the htaccess file).

The mod_alias - redirect[^] you have tried is not working for files:
Quote:

旧的URL路径是一个区分大小写(%-decoded)的路径,以斜杠开头

The old URL-path is a case-sensitive (%-decoded) path beginning with a slash





我不知道你真正想要实现的目标。但是如果目录列表已启用并且您想要从 index.php 重定向到目录,只需在该文件中通过向HTML输出的标题添加类似内容来执行此操作:



I don't know what you really want to achieve. But if directory listings are enabled and you want to redirect from index.php to the directory, just do it within that file by adding something like this to the header of the HTML output:

<meta http-equiv="refresh" content="0; url=/afolder/bfolder/" />



但请注意文件 index.php 必须在这种情况下,不能与 directoryindex 选项一起列出。


But note that the file index.php must not be listed with the directoryindex option in this case.


这篇关于使用htaccess或PHP或任何东西重定向访问者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆