.htaccess 重定向到 index.php [英] .htaccess redirect to index.php
问题描述
我的网站:theexample.com我修改了我的 .htaccess 以便如果访问者访问一个未知的 url,它会直接重定向到 index.php :
My website : theexample.com I modified my .htaccess so that if visitors visits an unkown url it redirects directly to index.php with :
FallbackResource index.php
问题是它只有在theexample.com"后面有一个元素时才有效.
The problem is that it works only if there is one element after "theexample.com".
例如:
"theexample.com/shudhusdfuisdfhisdfh":有效并重定向到
"theexample.com/shudhusdfuisdfhisdfh": works and redirects to
"theexample.com/sh/fuisd/fhisdfh": 不工作也不行重定向到 index.php.
"theexample.com/sh/fuisd/fhisdfh": doesn't work and doesn't redirect to index.php.
推荐答案
您必须使用回退资源的绝对路径,而不是相对路径:
You must use absolute path of fallback resource not a relative one:
FallbackResource /index.php
否则 FallbackResource index.php
将尝试在提供的子路径中加载 index.php
,例如theexample.com/sh/fuisd/fhisdfh
将尝试加载 theexample.com/sh/fuisd/index.php
这将导致失败,因为该路径不存在导致内部服务器错误.
Otherwise FallbackResource index.php
will try to load index.php
in the provided sub-path e.g. theexample.com/sh/fuisd/fhisdfh
will try to load theexample.com/sh/fuisd/index.php
which will cause failure as that path doesn't exist resulting in Internal Server Error.
这篇关于.htaccess 重定向到 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!