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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!