重定向每个请求的index.php和跨preT请求 [英] redirect every request to index.php and interpret the request

查看:155
本文介绍了重定向每个请求的index.php和跨preT请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Apache 2.2和PHP 5.3.8。 我应该如何配置的.htaccess重定向每个请求做的index.php?

I'm using Apache 2.2 and PHP 5.3.8. How should I configure .htaccess to redirect every request do index.php?

我想有网址像计算器或Facebook,因为: http://mywebsite.com/fancypage 其中,fancypage是不是在服务器上的目录,而只是一个参数。

I'd like to have URLs like those of stackoverflow or facebook, as: http://mywebsite.com/fancypage where fancypage isn't a directory on the server but just a parameter.

所以我想我需要重定向每个请求的PHP页面,其中一些code可跨preT的$ _ SERVER ['REQUEST_URI']字符串。这是正确的方式?将$ _ SERVER ['REQUEST_URI']重定向后仍然可用?

So I thought I needed to redirect every request to a php page, where some code can interpret the $_SERVER['REQUEST_URI'] string. Is this the right way? will $_SERVER['REQUEST_URI'] still be available after the redirection?

推荐答案

尝试添加以下到您的网站的根目录下的.htaccess文件。

Try adding the following to the .htaccess file in the root directory of your site.

这将发送所有的请求(除现有的文件/显示目录)到的index.php。

It will send all requests (except for existing files/dirs) to index.php.

原来的请求将在要求提供参数。

RewriteEngine On
RewriteBase /

#skip existing files or directories
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
#everything else goes to index.php
RewriteRule ^ index.php?request=%{THE_REQUEST} [L]

这篇关于重定向每个请求的index.php和跨preT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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