Htaccess无法重定向到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. 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. So the .htaccess file does not work. I have to mention that im trying to do that locally, having wamp installed and using slim framework. I do not know if something mess with these.

The code that i have in my .htaccess

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

展开翻译

译文

我试图在我的根文件夹中有一个htacess文件,这样我就可以将用户重定向到index.php文件,如果 例如,尝试访问我的根目录中的任何文件。 我做不到。 我应该在我的根文件夹中有该文件,但是当我试图访问在URL中键入名称的文件时,我实际上可以访问这些文件。 所以.htaccess文件不起作用。
我必须提到我试图在本地执行此操作,安装wamp并使用slim框架。 我不知道是否有些东西搞砸了。</ p>

我的.htaccess中的代码</ p>

  RewriteEngine on 
RewriteCond%{ REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^ index.php [L]
</ code> </ pre>
</ div>

php

1个回答

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

That means you want even the existing files not to be shown, and all requests should be redirected to 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. No wonder for files that are actually present your redirect is not working. You told it so.

展开翻译

译文




我在我的根文件夹中有我应该的文件,但是当我试图访问文件时输入名字 URL,我实际上可以访问文件</ p>
</ blockquote>

这意味着您甚至不希望显示现有文件,并且所有请求都应该重定向到index.php 。 </ p>

如果是这种情况,为什么你有这些条件? 删除这些</ p>

  RewriteCond%{REQUEST_FILENAME}!-d 
RewriteCond%{REQUEST_FILENAME}!-f
</ code> </ pre>

这两个条件意味着只有在请求的URL不是文件或目录时才应用重定向。 难怪实际存在的文件您的重定向不起作用。 你这么说了。</ p>
</ div>

du127953
du127953 哦,非常感谢Hanky! 你说得对,我不知道实际上我是在告诉他们展示内容。 我做了你说的,我删除了RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_FILENAME}! - f,但不是它不会重定向到index.php。 我只是有404错误!
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问