使用的.htaccess重新路由通过index.php的所有请求除一组特定的请求 [英] Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests

查看:224
本文介绍了使用的.htaccess重新路由通过index.php的所有请求除一组特定的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我只是继承了一个网站。我想做的第一件事是建立一个可爱的小标,易peezy,CMS允许与任何URL创建一个页面(例如:whatever.html)。

So I just inherited a site. The first thing I want to do is build a nice little standard, easy-peezy, CMS that allows for creating a page with any URL (for example: whatever.html).

因此​​,如果用户点击example.com/whatever.html,它应该获得whatever.html任何数据库信息,并显示出来。这是运行的轧机的东西。

Therefore, if user hits example.com/whatever.html, it should get any db info for whatever.html and display it. This is run of the mill stuff.

我的问题是,有在需要继续访问该网站(在所有的.htaccess中列出)比较了几页。例如,/促销链接通过的.htaccess promotions.php,我需要它保持这种方式。

My problem is that there are quite a few pages on the site (all listed in the .htaccess) that need to continue to be accessible. For instance, /Promotions is linked to promotions.php via .htaccess, and I need it to stay that way.

任何人都知道我可以构建.htaccess文件,以允许特定的重写仍然工作,但通过index.php来重新路由所有其他的要求吗?

Anyone know how I can construct the .htaccess file to allow specific rewrites to still work but to reroute all other requests through index.php?

目前,我只是表现的.htaccess自定义404页这反过来又检查了数据库的URL,如果它存在的显示。这是一个简单的解决方案,但我知道,有些人奇怪的浏览器工具栏(哑与否,他们存在:)),其autoredirect 404,和我讨厌不容许访问某些网页激怒我的用户使用这些工具栏。

Currently, I just have .htaccess show a custom 404 page which in turn checks the db for the url and displays it if it exists. This is an easy solution, but I know that some people have weird browser toolbars (dumb or not, they exist :) ) that autoredirect 404s, and I'd hate to annoy my users with these toolbars by not allowing access to certain pages.

非常感谢您的帮助!

推荐答案

重写规则的促销活动应该还是工作,因为它不是404ing。

The RewriteRule for promotions should still work as it's not 404ing.

如果该404处理器是显示的页面,因为它存在于数据库中,那么它应该真的会返回一个 200 OK 状态(覆盖404之一),所以你应该没有得到任何问题,浏览器工具栏。

If the 404 handler is showing the page because it exists in the database then it should really be returning a 200 OK status (overriding the 404 one), so you should not get any issues with browser toolbars.

至于做重路由,你可以做这样的事情:

As for doing the rerouting you can do something like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(promotions|anotherone|somethingelse)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?p=$1

这篇关于使用的.htaccess重新路由通过index.php的所有请求除一组特定的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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