开发者

mod_rewrite - Send everything that doesn't exist to index.php

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

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!


You are almost there:

Options +FollowSymLinks
RewriteEngine On

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

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜