我有一个简单的mod_rewrite规则,它允许我将任何不是实际文件或目录的请求重定向到index.php文件
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
在PHP文件中,我放了这个简单的代码来处理这个导航
<?php
$navString = $_SERVER['REQUEST_URI']; // Returns "/Mod_rewrite/edit/1/"
$parts = explode('/', $navString); // Break into an array
// Lets look at the array of items we have:
print_r($parts);
?>
我的开发环境是XAMPP和Windows 7-64位httpd.conf文件
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/xampp/cgi-bin">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
我的问题是,当我把任何变量传递给scrip时,例如
http://locahost/test/somethinghere/andhere
它将我重定向到本地主机默认页面,即
http://locahost/xampp
以下是关于如何在examplep中启用.htaccess mod_rewrite的说明。
-
在文本编辑器中打开并编辑C:''xamplep''apache''conf''httpd.conf
-
查找包含的行
#LoadModule rewrite_module modules/mod_rewrite.so
和(取消注释)更改为
LoadModule rewrite_module modules/mod_rewrite.so
-
查找的所有出现
AllowOverride None
并更改为
AllowOverride All
-
重新启动examplep
就这样,你应该很乐意去。
帮助:http://www.leonardaustin.com/blog/technical/enable-mod_rewrite-in-xampp/
已解决我刚刚将文件夹添加到.htaccess并删除Options+SymLinksIfOwnerMatch
RewriteBase /test/
重写规则可以通过httpd.conf或.htaccess文件启用
关于如何在wamp/xamplep中启用.htaccess mod_rewrite的说明
步骤1:转到安装目录:C:'xampp>'apache'conf
或C:'wamp'bin'apache'Apache2.2.11'conf
步骤2:在文本编辑器中打开httpd.conf
步骤3:查找包含#LoadModule rewrite_module modules/mod_rewrite.so
步骤4:从行的开头删除(#)以启用模块
步骤5:现在更改AllowOverride None
的所有出现并替换为AllowOverride All
步骤6:现在重新启动服务器