0

我正在从 zeus 平台迁移到 apache,并且在以下重写时遇到问题:

/12345-somepage.html
/event.php?ref=12345

这是.htaccess

RewriteEngine  on
RewriteRule    ^/([0-9]*)- /event.php?ref=$1 <-- This doesn't work 404 not found
RewriteRule    ^otherpage.htm  index.php?Month=0&Category=otherpage <- This one works

这是现有的宙斯重写规则:

match URL into $ with ^/([0-9]*)-
if matched then set URL = /event.php?ref=$1

我已经验证目标地址有效,即/event.php?ref=12345

4

1 回答 1

1

您的默认值RewriteBase/,这就是您不匹配前导的原因/,设置RewriteBase以防止意外行为,添加修饰符[L]以便 Apache 在匹配后停止处理以下重写,添加[QSA]以附加来自原始 url 的查询字符串

这有效:

RewriteEngine On
RewriteBase /

RewriteRule    ^([0-9]+)- /event.php?ref=$1 [L,QSA]

我的事件.php

<?php 
echo $_SERVER['PHP_SELF'];
echo "\n";
print_r( $_GET ); 
?>

输出

# curl -i http://localhost/1234-mypage.html
HTTP/1.1 200 OK
Date: Sat, 01 Dec 2012 22:57:28 GMT
Content-Type: text/html

/event.php
Array
(
    [ref] => 1234
)
于 2012-12-01T22:59:34.393 回答