dpl57372 2013-04-24 00:18
浏览 69
已采纳

Apache mod_rewrite没有将表达式映射到参数

I have a site which uses apache mod_rewrite and has been working for the last 6 months with no error.

I have the following rewrite rule:

RewriteRule ^products/([a-z\-]+)/$ /products.php?category=$1 [NC,L]

Here is the code in my page products.php

$category = $_GET['category'];

if (isset($category)) {
    // do some processing here
}
else {
    header("Location: /500.html");
    exit;
}

An example of a link which hits this rule is /products/lighting-poles/

Does anyone know why the actual rewrite is still occurring but not mapping the ([a-z\-]+) to category=$1?

Extra info

I noticed that the .htaccess file on the host has commented out the line Options +FollowSymLinks so I first tried to re-enable this only to have the site return an apache white screen 500 error.

More from the .htaccess file

<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

# other rules including problem rule here

</IfModule>
  • 写回答

1条回答 默认 最新

  • douwei1921 2013-04-24 02:46
    关注

    This sounds morbidly like a multiviews issue. Multiviews is a content-negotiation thing where if it's turned on, it'll try a few different extra things in the URL-file mapping pipeline to try to find a file that maps to a URL. Here you have a URL like /products/blah, yet, you have a file called products.php, so multiviews might try to map products to /products.php/blah. Thus bypassing the rewrite rule entirely, and you don't see the category parameter.

    Where the options are, try adding:

    Options -Multiviews
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员