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

查看:284
本文介绍了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~~V

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,然后将其重定向到/ EG。 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]

这将重定向所有不符合 / /

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

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