apache - .htaccess 重写参数未传递到目标页面

标签 apache .htaccess mod-rewrite centos varnish

我想传递 url 参数,但参数没有传递到所需的页面。

早些时候,我的网站托管在 cpanel 上,下面的代码成功运行,但在我将我的网站转移到 VPS 服务器后,使用 Cent OS Webpanel 并在服务器上运行 Varnish Cache 和 apache,参数不会在目标页面/url 上传递。

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  

RewriteRule ^download/(.*).html download.php?q=$1 [L,QSA]

我想运行 url:www.example.com/download/anything.html
重写后的目标 url 是 www.example.com/download.php?q=anything
问题是 rewriterule 正在工作,但没有传递参数。

但是如果我使用下面的代码,参数就会成功传递。

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  

RewriteRule ^([a-zA-Z_0-9-]+)$ download.php?q=$1 [L,QSA]

或以下代码

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*) download.php?q=$1 [L,QSA]

我正在运行下面的 url,参数已成功传递到目标页面
www.example.com/anything
目标网址:www.example.com/download.php?q=anything


但我想要以下格式的 URL www.example.com/download/*****.html 用实际查询替换 *Asterisk Sign。

如果我向 Rewrite url 添加一些静态文本,如 download/(.*).html,则参数不会传递到目标页面。

谢谢

最佳答案

很可能新服务器默认启用了 MultiViews 选项。将此行放在 .htaccess 之上以禁用它:

Options -MultiViews

选项 MultiViewsApache 的内容协商模块 使用,该模块在 mod_rewrite 之前运行,并使 Apache 服务器匹配文件的扩展名。所以 /file 可以在 URL 中,但它将服务于 /file.php

关于apache - .htaccess 重写参数未传递到目标页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716246/

相关文章:

.htaccess 替换单词并重定向

apache - 如何通过htaccess将目录中的所有文件重定向到root中的另一个

.htaccess - 收到错误 "Invalid command ' SSLProxyCheckPeerCN'

php - 我们的 Centos 服务器感染了一些恶意软件。它正在调用随机 IP/域。如何阻止服务器发出外部请求?

apache - HRegionServer 显示 "error telling master we are up"。显示套接字异常 : Invalid argument

php - 在apache服务器上运行exe文件

.htaccess - CakePHP 和 AngularJs 中的路由和谐 : htaccess rules to send user to index. html 或 bootstrap index.php

php - .htaccess 重写规则破坏 css

regex - 重写 htaccess 中多次出现的术语

php - Centos 7 Apache 和 PHP5 错误 : Package: php-5. 6.40-21.el6.remi.x86_64 (remi-php56)