将任何可能的域请求重定向到根

时间:2015-02-26 16:56:26

标签: .htaccess

我有mydomain.com。我希望将任何请求重定向到根目录:mydomain.com或mydomain.com/index.html

任何要求 - 我的意思是一切。可以请求:

mydomain.com?hello
mydomain.com/subdir/ (im not sure if that will conflict with linking to assets in my index.html?)
mydomain/gwegewgewgew/
mydomain.com/hello.jpg
etc

我尝试过以下但没有运气:

RewriteEngine On

# It is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# It is a directory 
RewriteCond %{REQUEST_FILENAME} -d
# If request is for other than root then route to /
RewriteRule .+ / [L]

如果我尝试请求:mydomain.com/teteetegeg - 我得到:"在此服务器上找不到请求的URL / teetege。"

检查了mod_rewrite是否出现在带有php info的已加载模块下。

1 个答案:

答案 0 :(得分:0)

尝试改为:

RewriteEngine On
RewriteCond $1 !^(?:index\.html)$
RewriteRule ^(.*)$ / [L,R]

或者,您可以使用后备资源:

FallbackResource /
相关问题