简体   繁体   English

使用mod_rewrite与XAMPP和Windows 7 - 64位?

[英]using mod_rewrite with XAMPP and windows 7 - 64 bit?

i have a simple mod_rewrite rule which allow me to re-direct any requests that are not actual files or directories to the index.php file 我有一个简单的mod_rewrite规则,允许我将任何非实际文件或目录的请求重定向到index.php文件

    Options +SymLinksIfOwnerMatch 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

in PHP file i put this simple code to handle this navigation 在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);
?>

my development environment is XAMPP and Windows 7 - 64 bit httpd.conf file 我的开发环境是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>

my problem is when ever i pass any varible to the scrip for example 我的问题是,当我将任何变量传递给脚本时,例如

http://locahost/test/somethinghere/andhere

it redirect me to the local host default page which is 它将我重定向到本地主机默认页面

http://locahost/xampp

Below are the instructions on how to enable .htaccess mod_rewrite in xampp. 以下是如何在xampp中启用.htaccess mod_rewrite的说明。

  1. Open and edit C:\\xampp\\apache\\conf\\httpd.conf in a text editor 在文本编辑器中打开并编辑C:\\ xampp \\ apache \\ conf \\ httpd.conf

  2. Find the line which contains 找到包含的行

     #LoadModule rewrite_module modules/mod_rewrite.so 

    and (uncomment) change to 和(取消注释)更改为

     LoadModule rewrite_module modules/mod_rewrite.so 
  3. Find all occurrences of 查找所有出现的

     AllowOverride None 

    and change to 并改为

     AllowOverride All 
  4. Restart xampp 重启xampp

That's it you should be good to go. 那就是你应该好好去。

Help: http://www.leonardaustin.com/blog/technical/enable-mod_rewrite-in-xampp/ 帮助: http//www.leonardaustin.com/blog/technical/enable-mod_rewrite-in-xampp/

解决了我刚刚将文件夹添加到.htaccess并删除Options + SymLinksIfOwnerMatch

RewriteBase /test/

A rewrite rule can be enabled through in httpd.conf or in .htaccess file. 可以通过httpd.conf.htaccess文件启用重写规则。
Instructions on how to enable .htaccess mod_rewrite in wamp/xampp 有关如何在wamp / xampp中启用.htaccess mod_rewrite的说明

Step 1: Go to the directory of installation : 第1步:转到安装目录:
C:\\xampp>\\apache\\conf or C:\\wamp\\bin\\apache\\Apache2.2.11\\conf C:\\xampp>\\apache\\confC:\\wamp\\bin\\apache\\Apache2.2.11\\conf
Step 2: Open httpd.conf in a text editor 第2步:在文本编辑器中打开httpd.conf
Step 3: Find the line which contains #LoadModule rewrite_module modules/mod_rewrite.so 第3步:找到包含#LoadModule rewrite_module modules/mod_rewrite.so
Step 4: Remove (#) from start of line to make module enable 步骤4:从行开始删除(#)以使模块启用
Step 5: Now Change all occurrences of AllowOverride None and replace to AllowOverride All 步骤5:现在更改所有出现的AllowOverride None并替换为AllowOverride All
Step 6: Now restart wamp/xampp server 第6步:现在重启wamp / xampp服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM