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 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题