【问题标题】:Rewrite not working with xampp重写不适用于 xampp
【发布时间】:2013-10-20 07:57:13
【问题描述】:

这个简单的重写不起作用。我已经在运行 linux 的服务器上对此进行了测试,并且可以正常工作。 http://www.lokislayer.com/mvc/bob -- 页面显示 bob 应有的样子 --

localhost 不适用于已安装的 xampp:

.htaccess 文件

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

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]enter code here

简单的 index.php 文件

<?php
   $url = $_GET['url'];
   echo $url;
 ?>

来自 php 的错误消息: 注意:未定义索引:第 3 行 E:\XAMPP\htdocs\mvc\source\index.php 中的 url

除非我删除第二个 RewriteCond,否则代码不起作用。我确实有 mod rewrite 工作,因为在同一个 xampp 安装上我正在运行 MagentoCE 1.8。

【问题讨论】:

    标签: php .htaccess xampp


    【解决方案1】:

    确保将上面的代码放在DOCUMENT_ROOT/mvc/source/.htaccess 中,并且你的代码是这样的:

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    RewriteBase /mvc/source/
    
    RewriteRule ^([^.]+)/?$ index.php?url=$1 [QSA,L]
    

    重要的变化是RewriteBase的使用

    【讨论】:

    • 还是不行吗?我的项目在 DOCUMENT_ROOT/mvc/source 中。我什至复制了您的确切措辞,但仍然无法在索引中找到 $url,即使它适用于我的 linux apache 环境。
    • 好的,我进行了编辑。上面的代码应该在DOCUMENT_ROOT/mvc/source/.htaccess。试试看。
    • 还是不行。如果我删除 RewriteCond %{REQUEST_FILENAME} -f 行,它会起作用,因为我已尝试删除该行。它可以工作,但不像在 linux 服务器上那样工作。
    • 好的,对于哪个 URL,它不能按您的预期工作?尝试提供尽可能多的细节,以便我可以更好地帮助您。您的系统中是否有任何其他 .htaccess 或此 .htaccess 中的任何其他规则?我也进行了编辑,尝试编辑代码。
    猜你喜欢
    • 1970-01-01
    • 2016-05-02
    • 2011-03-04
    • 2011-10-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    相关资源
    最近更新 更多