URL重写未映前pression为参数 [英] Apache mod_rewrite not mapping expression to parameter

查看:180
本文介绍了URL重写未映前pression为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,它使用 URL重写,并一直致力于为过去6个月,没有错误。

我有以下重写规则:

 重写规则^产品/(即[az \  - ] +)/ $ /products.php?category=$1 [NC,L]
 

下面是code。在我的网页 products.php

  $类别= $ _GET ['类'];

如果(使用isset($类别)){
    //做一些处理这里
}
其他 {
    标题(位置:/500.html);
    出口;
}
 

这打这个规则链接的一个例子是 /产品/照明灯杆/

有谁知道为什么实际的重写仍然存在,但不映射(即[az \ - ] +)类= $ 1

额外的信息

我注意到的.htaccess 主机上的文件已注释掉行选项+了FollowSymLinks 让我第一次试图重新启用此只为有现场返回一个Apache白色屏幕 500 错误。

更多来自.htaccess文件

 < IfModule mod_rewrite.c>
#Options +的FollowSymLinks
RewriteEngine叙述上
的RewriteBase /

#添加斜线为路径不带扩展名
的RewriteCond%{REQUEST_METHOD}!POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{REQUEST_URI}!(\ [A-ZA-Z0-9] {1,5} | /)$
重写规则^(。*)$ $ 1 / [L,R = 301]

#其他规则,包括这里的问题规则

< / IfModule>
 

解决方案

这听起来病态像一个多视图的问题。多视图是内容协商东西在那里,如果它打开时,它会尝试在URL文件映射管道几个不同的额外的东西,试图找到映射到一个URL文件。在这里,你有一个像的URL /产品/等等,但是,你有一个名为 products.php ,所以多视图可以尝试映射产品 /products.php/blah 。从而绕过重写规则完全,你看不到参数。

当选项,试着加入:

 选项-Multiviews
 

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>

解决方案

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

这篇关于URL重写未映前pression为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆