简体   繁体   English

Htaccess 无法重定向到 index.php

[英]Htaccess fail to redirect to index.php

Im trying to have a htacess file within my root folder so i can redirect the user to index.php file, if for example trying to access any file inside my root directory.我试图在我的根文件夹中有一个 htacess 文件,以便我可以将用户重定向到 index.php 文件,例如,如果尝试访问我的根目录中的任何文件。 I failed to do that.我没能做到。 I have that file inside my root folder as i should, but when im trying to access files typing the names in the URL, i actually have access to the files.我应该在我的根文件夹中保存该文件,但是当我尝试访问在 URL 中输入名称的文件时,我实际上可以访问这些文件。 So the .htaccess file does not work.所以 .htaccess 文件不起作用。 I have to mention that im trying to do that locally, having wamp installed and using slim framework.我不得不提一下,我试图在本地做到这一点,安装了 wamp 并使用了超薄框架。 I do not know if something mess with these.我不知道这些是否有问题。

The code that i have in my .htaccess我的 .htaccess 中的代码

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I have that file inside my root folder as i should, but when im trying to access files typing the names in the URL, i actually have access to the files我应该在我的根文件夹中有那个文件,但是当我尝试访问在 URL 中输入名称的文件时,我实际上可以访问这些文件

That means you want even the existing files not to be shown, and all requests should be redirected to index.php.这意味着您甚至希望不显示现有文件,并且所有请求都应重定向到 index.php。

If that is the case then why do you have these conditions?如果是这样,那么为什么你有这些条件? Remove these删除这些

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

Those 2 conditions mean apply that redirect only if the requested url is niether a file nor a directory.这两个条件意味着仅当请求的 url 既不是文件也不是目录时才应用该重定向。 No wonder for files that are actually present your redirect is not working.难怪对于实际存在的文件,您的重定向不起作用。 You told it so.你是这么说的。

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

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