htaccess - 将所有请求重定向到域根 [英] htaccess - redirecting all requests to domain root

查看:28
本文介绍了htaccess - 将所有请求重定向到域根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不再需要上线的网站,并且有一个保留页面设置来声明它不再可用.对站点页面(书签或其他)的所有请求都需要发送到这个页面,即根 index.php 页面,所以我使用一些 htaccess 相应地重定向它.

I have a site that is no longer needed live and has a holding page setup to state that it's no longer available. All requests to pages on the site (bookmarked or otherwise) need to be sent to this page which is the root index.php page, so I'm using some htaccess to redirect it accordingly.

我目前正在使用这个:

RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ /index.php [R=302,NC,L]

完成这项工作,但将 index.php 添加到 url - 即.www.domain.com 转到 www.domain.com/index.php

which does the job, but adds index.php to the url - ie. www.domain.com goes to www.domain.com/index.php

如果只有 www.domain.com 会好得多,但显然我不能这样做:

It'd be much nicer to have just www.domain.com, but apparently I can't do that using:

RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ / [R=302,NC,L]

它导致页面无法在 Firefox 中正确重定向.

It gives a page not redirecting properly error in firefox.

我希望上面能检查 REQUEST_URL 是否不是/- 即.www.domain.com 然后将其重定向到/例如.www.domain.com/dave.php -> www.domain.com - 因此 www.domain.com 通过,但其他所有内容都被重定向......它实际在做什么以及如何让它做我想要的?

I'd have expected the above to check to see if the REQUEST_URL isn't / - ie. www.domain.com and then redirect it to / eg. www.domain.com/dave.php -> www.domain.com - thus www.domain.com passes, but everything else is redirected... what's it actually doing and how to I get it to do what I want it to?

推荐答案

就这样使用它:

RewriteRule ^.+$ / [R=302,NC,L]

它会将所有不匹配 / 的内容重定向到 /.

It will redirect all that don't match / only to /.

这篇关于htaccess - 将所有请求重定向到域根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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