【问题标题】:How to redirect everything internally using htaccess and mod_rewrite?如何使用 htaccess 和 mod_rewrite 在内部重定向所有内容?
【发布时间】:2011-09-17 21:04:13
【问题描述】:

我想使用单个 php 脚本处理对域的所有请求。

例如:

www.domain.com/something.php -> would be loading -> www.domain.com/process.php?u=something.php
www.domain.com/anything      -> would be loading -> www.domain.com/process.php?u=anything
www.domain.com/sub/dir/x     -> would be loading -> www.domain.com/process.php?u=sub/dir/x

但是 process.php 不应该直接在浏览器上打开,我想做一个内部重定向。

谁能告诉我如何使用 htaccess 和 mod_rewrite 来做到这一点?

【问题讨论】:

    标签: .htaccess url mod-rewrite redirect url-rewriting


    【解决方案1】:

    将这些行放入您的 .htaccess 文件中:

    RewriteEngine On
    RewriteRule (.*) process.php?u=$1 [QSA,L]
    

    这将告诉 Apache 使用 process.php 而不是实际请求的页面。

    您很可能还需要在 RewriteRule 行之前添加这些行,以告诉 Apache 按原样处理现有文件,否则您的 images/css/javascript 文件也将由 process.php 处理

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      相关资源
      最近更新 更多