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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵