我的mod_rewrite规则不解析PHP变量

时间:2016-01-28 14:24:39

标签: php apache .htaccess mod-rewrite url-rewriting

我有一个有趣的情况。我已经配置了一个基本的LAMP服务器,外部公司正在为我们提供一些代码。一切都有效,除了PHP专门改写。

我已经成功配置了重写,并且可以执行基本的重写,例如hello.html - > redir.html。 我也通过将LogLevel转到trace6来确认这一点,并且我看到重写处于活动状态。

麻烦来自php变量。它似乎只是没有解决它们。

我有以下简化的.htaccess文件,其中删除了所有其他规则以进行测试

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^news/(.*)/(.*)/(.*)/$ news.php?department=$1&newsid=$2&newstitle=$3 [L]
RewriteRule ^$ index.php?page=home [L]

</ifModule>

现在,如果我输入我的网址 http://webserver/news/it/153/newsstory

我希望被重定向到

http://webserver/news.php?department=it&newsid=153&newstitle=newsstory

但是,第二条规则会抓住它。

这对我来说很棘手,因为我提供服务器基础设施而不是编写代码(外部提供)。我们的代码供应商表示,他们的工作方式很有效,而且我们已经看到了工作演示,所以我一直在尝试从“我们丢失的软件包或配置”进行故障排除&#39;角度。

据我所知,如果mod_rewrite工作,它应该......工作。

错误redir的日志转储

[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/news.php -> /var/www/itnews/news.php/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/news.php/it/153/newsstory -> news.php/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'news.php/it/153/newsstory'
[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/news.php -> /var/www/itnews/news.php/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/news.php/it/153/newsstory -> news.php/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'news.php/it/153/newsstory'
[perdir /var/www/itnews/] pass through /var/www/itnews/news.php
[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/news.php -> /var/www/itnews/news.php/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/news.php/it/153/newsstory -> news.php/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'news.php/it/153/newsstory'
[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/news.php -> /var/www/itnews/news.php/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/news.php/it/153/newsstory -> news.php/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'news.php/it/153/newsstory'
[perdir /var/www/itnews/] pass through /var/www/itnews/news.php
[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/it -> /var/www/itnews/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/it/153/newsstory -> it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'it/153/newsstory'
[perdir /var/www/itnews/] add path info postfix: /var/www/itnews/it -> /var/www/itnews/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/it/153/newsstory -> it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'it/153/newsstory'
[perdir /var/www/itnews/] pass through /var/www/itnews/it
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/images/logo.jpg -> images/logo.jpg, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'images/logo.jpg', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/images/logo.jpg -> images/logo.jpg, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'images/logo.jpg', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/images/logo.jpg, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/bootstrap.min.css -> css/bootstrap.min.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'css/bootstrap.min.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/bootstrap.min.css -> css/bootstrap.min.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'css/bootstrap.min.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/css/bootstrap.min.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/style.css -> css/style.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'css/style.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/style.css -> css/style.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'css/style.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/css/style.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/js/bootstrap.min.js -> js/bootstrap.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'js/bootstrap.min.js', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/js/bootstrap.min.js -> js/bootstrap.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'js/bootstrap.min.js', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/js/bootstrap.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/prettyCheckable.css -> css/prettyCheckable.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'css/prettyCheckable.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/css/prettyCheckable.css -> css/prettyCheckable.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'css/prettyCheckable.css', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/css/prettyCheckable.css, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/js/jquery-1.11.0.min.js -> js/jquery-1.11.0.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'js/jquery-1.11.0.min.js', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/js/jquery-1.11.0.min.js -> js/jquery-1.11.0.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'js/jquery-1.11.0.min.js', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/js/jquery-1.11.0.min.js, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/plugins/timthumb.php -> plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'plugins/timthumb.php', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/plugins/timthumb.php, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/fonts/ocean_sans_std_book-webfont.woff -> fonts/ocean_sans_std_book-webfont.woff, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^news/(.*)/(.*)/(.*)$' to uri 'fonts/ocean_sans_std_book-webfont.woff', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/fonts/ocean_sans_std_book-webfont.woff -> fonts/ocean_sans_std_book-webfont.woff, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] applying pattern '^$' to uri 'fonts/ocean_sans_std_book-webfont.woff', referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] pass through /var/www/itnews/fonts/ocean_sans_std_book-webfont.woff, referer: http://webserver/news/it/153/newsstory
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/images/body-bg.jpg -> images/body-bg.jpg, referer: http://webserver/css/style.css?v=1.0.1
[perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/images/body-bg.jpg -> images/body-bg.jpg, referer: http://webserver/css/style.css?v=1.0.1
[perdir /var/www/itnews/] applying pattern '^$' to uri 'images/body-bg.jpg', referer: http://webserver/css/style.css?v=1.0.1
[perdir /var/www/itnews/] pass through /var/www/itnews/images/body-bg.jpg, referer: http://webserver/css/style.css?v=1.0.1

相关:我刚刚浏览了所有可以找到的php页面,并将错误记录打开到最大值。

我正在

Notice: Undefined index: department in /var/www/itnews/news.php on line 15

Notice: Undefined index: newsid in /var/www/itnews/news.php on line 18

Notice: Undefined index: archive in /var/www/itnews/pages/news-archive.php on line 16

Notice: Undefined variable: page in /var/www/itnews/pages/news-archive.php on line 28
主页上的

。我现在认为php中的某些内容出错并且重定向实际上是失败的,因为php本身无法解析其变量。

这可能吗?

1 个答案:

答案 0 :(得分:1)

由于最后http://webserver/news/it/153/newsstory,此网址/无法与您的第一条规则匹配。

# do not match
RewriteRule ^news/(.*)/(.*)/(.*)/$ news.php?department=$1&newsid=$2&newstitle=$3 [L]

# will match
RewriteRule ^news/(.*)/(.*)/(.*)$ news.php?department=$1&newsid=$2&newstitle=$3 [L]

您可以使用this tool调试.htaccess个文件。