0

我的文件夹/文件结构为:

rootFolder/
  lowRes/lowres.php
  hiRes/hires.php
  sys.php

基本上,我想做重写,例如当用户调用页面site.com/img_0001_hq.html,.htaccess 将其重写为sys.php?1=img_0001_hq。此外,我想将可接受的 emdings 限制为“.html”和“/”,如果不存在这样的结尾,我想调用 sys.php?1=p_404。重写按预期进行,但是当涉及到错误时......

当我调用页面 site.com/hiRes/hires.php 或 site.com/lowRes/lowres.php 时,重写不起作用,脚本(hires.php 和 lowres.php)运行,并报告错误,通常缺少变量来自未触发的 sys.php。此外,当我调用页面 site.com/hiRes 或 site.com/lowRes 时,sys.php 运行,但是,错误。此外,调用这些地址时,浏览器中的地址会更改为 site.com/hiRes/?1=p_404 或 site.com/lowRes/?1=p_404。到底他妈发生了什么?!:D

哦,是的,我的 .htaccess 看起来像这样:

IndexIgnore *
RewriteEngine on
RewriteRule ^(.*)(/|.html)$ sys.php?1=$1 [L]
RewriteRule ^(.*)$ sys.php?1=p_404 [L]

我要疯了... :)

4

1 回答 1

0

尝试添加一些排除 sys.php 的条件(以及您不想重写的任何其他内容)。可能发生的情况是,在第一次重写后,URI 变为sys.php并通过重写引擎放回(mod_rewrite 将执行此操作,直到 URI 停止更改或达到内部重定向的最大数量,导致 500 服务器错误):

IndexIgnore *
RewriteEngine on

RewriteCond %{REQUEST_URI} !sys\.php
RewriteRule ^(.*)(/|.html)$ sys.php?1=$1 [L]

RewriteCond %{REQUEST_URI} !sys\.php
RewriteRule ^(.*)$ sys.php?1=p_404 [L]
于 2013-04-18T03:27:02.880 回答