【问题标题】:mod_rewrite - Send everything that doesn't exist to index.phpmod_rewrite - 将不存在的所有内容发送到 index.php
【发布时间】:2011-10-11 00:16:44
【问题描述】:

我想让我的 .htaccess 文件重写 index.php 文件中不存在的任何内容。例如:www.example.com/category/subcategory/product1/ 将被重写为 index.php?request=category/subcategory/product1

我想先检查目录是否存在,如果存在,不要重写。我现在有这样的东西,但只需要知道如何将请求的 URL 放入 PHP $_GET 变量中:

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

感谢任何帮助!

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    你快到了:

    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'] 访问原始(请求的)URL——唯一的区别是 REQUEST_URI 总是以斜杠开头(例如/category/subcategory/product1)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      相关资源
      最近更新 更多