【问题标题】:Apache rewrite for SEFsSEF 的 Apache 重写
【发布时间】:2012-11-08 16:28:09
【问题描述】:

如何让 index.php 处理请求

例如

如果我在浏览器中输入 SEF

http://localhost/friends
http://localhost/me

重写为

http://localhost/index.php/friends
http://localhost/index.php/me

所以我可以从 $_REQUEST['PATH_lNFO'] 访问朋友或我

我已经修改并允许在 apache 中为根目录设置所有指令。

需要一个 .htaccess 文件,

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    在这篇文章http://www.sitepoint.com/apache-mod_rewrite-examples/ 中查看此 RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ 显示.php?country=$1&state=$2&city=$3 [L]

    AddDefaultCharset UTF-8
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /rtest
    RewriteCond %{HTTP_HOST} ^mathpdq\.com
    RewriteRule ^(.*)$ http://www.mathpdq.com/rtest/$1 [R=permanent,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    

    http://mathpdq.com/rtest/fred

    【讨论】:

      【解决方案2】:
      RewriteRule ^friends$ index.php/friends [L]
      RewriteRule ^me$ index.php/me [L]
      

      就是这样。

      $_REQUEST['PATH_INFO'] 将设置为“/friends”或“/me”。

      (根据您的服务器配置,可能必须使用ORIG_PATH_INFO 而不是PATH_INFO)

      【讨论】:

        猜你喜欢
        • 2013-03-16
        • 1970-01-01
        • 2013-06-05
        • 2013-10-26
        • 1970-01-01
        • 1970-01-01
        • 2011-12-14
        • 2012-11-17
        • 2012-01-29
        相关资源
        最近更新 更多