【问题标题】:Apache Rewrite URL to index.php variableApache 将 URL 重写为 index.php 变量
【发布时间】:2014-03-08 09:05:49
【问题描述】:

我正在尝试将网站从一台主机迁移到另一台主机。当前主机具有非常旧版本的 PHP、Apache 和 MySQL。我在测试 Win XP VM 上安装了所有相同版本。该网站的 htaccess 如下所示:

RewriteEngine On

RewriteBase /  

  RewriteCond %{HTTP_HOST} ^test\.com [NC] 

   RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]

    RewriteRule ^(sales) index.php?main_page=page&id=2
    RewriteRule ^(support) index.php?main_page=page&id=3
    RewriteRule ^(about_me) index.php?main_page=page&id=4
    RewriteRule ^(help) index.php?main_page=page&id=5
    RewriteRule ^(site_map) index.php?main_page=site_map

谁能告诉我需要在 httpd.conf 中启用哪些选项才能正确重定向?目前,主页显示,但从主页菜单栏中单击的任何链接都显示错误。例如,在此服务器上找不到请求的 URL /sales。

【问题讨论】:

    标签: apache .htaccess windows-xp httpd.conf


    【解决方案1】:

    像这样编辑 .htacces 文件

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      我认为您只是缺少正斜杠和 $

      RewriteRule ^(sales) index.php?main_page=page&id=2
      

      应该是

      RewriteRule   ^(/sales)$ /index.php?main_page=page&id=2
      

      【讨论】:

        猜你喜欢
        • 2013-06-25
        • 1970-01-01
        • 2022-08-19
        • 2021-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多