重定向每个请求的index.php和跨preT请求重定向、index、preT、php

由网友(繁花落幕╭ァ那曲终人散)分享简介:我使用的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 d...

我使用的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]
阅读全文

相关推荐

最新文章