我正在从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这是现有的Zeus重写规则:
match URL into $ with ^/([0-9]*)-
if matched then set URL = /event.php?ref=$1我已验证目标地址有效,即/event.php?ref=12345
发布于 2012-12-02 06:59:34
您的默认RewriteBase是/,这就是您不匹配前导/的原因,设置RewriteBase以防止意外行为,添加修饰符[L]以便Apache在此匹配后停止处理以下重写,添加[QSA]以附加原始url中的查询字符串
这是可行的:
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)- /event.php?ref=$1 [L,QSA]我的event.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
)https://stackoverflow.com/questions/13664289
复制相似问题