mod_rewrite的 - 发送一个不存在的index.php一切 [英] mod_rewrite - Send everything that doesn't exist to index.php

查看:213
本文介绍了mod_rewrite的 - 发送一个不存在的index.php一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有我的.htaccess文件重写一个不存在的index.php文件什么。因此,例如: www.example.com/category/subcategory/product1 / 将被改写成的index.php请求=类别/子/产品1?

I would like to have my .htaccess file rewrite anything that doesn't exist to the index.php file. So for example: www.example.com/category/subcategory/product1/ would be rewritten to index.php?request=category/subcategory/product1

我要进行检查,看是否该目录存在一个内核,如果确实如此,不重写。我有这样的事情,此刻,而且只需要知道我如何能得到请求的URL到PHP $ _ GET 变量:

I want to perform a check to see if the directory exists first though, and if it does, do not rewrite. I have something like this at the moment, but just need to know how I can get the requested URL into the PHP $_GET variable:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php [L]

任何帮助高级感谢!

Advanced thanks for any help!

推荐答案

您几乎有:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]

TBH,没有真正必要把请求的URL为 $ _ GET 变量 - 你可以随时通过访问原始的(要求)网址 $ _ SERVER ['REQUEST_URI'] - 唯一的区别是, REQUEST_URI 将总是以斜线(如 /类别/子/产品1 )。

TBH, there is no real need to put requested URL into $_GET variable -- you can ALWAYS access original (requested) URL via $_SERVER['REQUEST_URI'] -- the only difference is that REQUEST_URI will always start with leading slash (e.g. /category/subcategory/product1).

这篇关于mod_rewrite的 - 发送一个不存在的index.php一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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