Php 如何修改.htaccess文件以提供查询字符串?

Php 如何修改.htaccess文件以提供查询字符串?,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我有下面的htaccess文件在我的网站,它是完美的工作在过去两年。最近,我将服务器迁移到了一个新的托管合作伙伴,它似乎没有按预期工作。我已经确认服务器支持mod_重写模块。我可以看到[QUERY_STRING]=>与我指定的URL一样为空,并且所有URL都路由到主页。有人能告诉我需要修改什么吗。我在stackoverflow中看到了很多答案,但对我来说没有任何效果。我只是这个htaccess文件中的乞丐 Options +FollowSymLinks RewriteEngine On Opti

我有下面的htaccess文件在我的网站,它是完美的工作在过去两年。最近,我将服务器迁移到了一个新的托管合作伙伴,它似乎没有按预期工作。我已经确认服务器支持mod_重写模块。我可以看到[QUERY_STRING]=>与我指定的URL一样为空,并且所有URL都路由到主页。有人能告诉我需要修改什么吗。我在stackoverflow中看到了很多答案,但对我来说没有任何效果。我只是这个htaccess文件中的乞丐

Options +FollowSymLinks
RewriteEngine On
Options -Indexes

# REWRITING index.php AS index #
RewriteRule   ^index/?$   index.php  [NC]

# Route The Pages #
RewriteRule   ^index/([{a-z}]+)/?$   index.php?$1  [NC,L]

RewriteRule   ^index/home/([0-9]+)/?$   index.php?home&p_id=$1  [NC,L]
RewriteRule   ^index/page/([{a-z}{\-\}{0-9}]+)/?$   index.php?page&show=$1  [NC,L]

RewriteRule   ^index/gallery/([{image}{video}]+)/?$   index.php?gallery&type=$1  [NC,L]
RewriteRule   ^index/gallery/([{image}{video}]+)/([0-9]+)/?$   index.php?gallery&type=$1&album=$2  [NC,L]

如果您正在匹配
视频
图像
,则没有理由使用
{video}
,因为
{
和}
将按字面意思匹配
{video}`

请通过以下方式访问.htaccess:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On

# REWRITING index.php AS index #
RewriteRule ^index/?$ index.php [NC,L]

# Route The Pages #
RewriteRule ^index/([a-z]+)/?$ index.php?$1 [NC,L,QSA]

RewriteRule ^index/home/([0-9]+)/?$ index.php?home&p_id=$1 [NC,L,QSA]

RewriteRule ^index/page/([a-z0-9-]+)/?$ index.php?page&show=$1 [NC,L,QSA]

RewriteRule ^index/gallery/(image|video)/?$ index.php?gallery&type=$1 [NC,L,QSA]

RewriteRule ^index/gallery/(image|video)/([0-9]+)/?$ index.php?gallery&type=$1&album=$2 [NC,L,QSA]
空查询字符串与启用的
MultiViews
一致(可能是服务器更新的结果)。尝试禁用
文件顶部的
多视图
。htaccess
文件:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
如果启用了
MultiViews
,则对
/index/
的请求将导致对
/index.php/
的内部子请求,并且剩余指令都不匹配



然而,您仍然需要更新您的正则表达式,使其符合anubhava的建议,因为您当前的正则表达式可能比您预期的要匹配得多。但你目前的模式是模棱两可的。例如,
[{a-z}{\-\}{0-9}]+
应该匹配什么?看起来您可能希望它是一个
-
?然而,它目前匹配字母、数字和连字符的任意组合(这就是anubhava对它的解释)

为什么图案中有花括号?你能告诉我一些不起作用的url吗?其中一个url是tgmvidyaniketan.edu.in/index/gallery/imageI,我正要发布完全相同的版本-@Ricky你可以在这里看到一个演示:我已经测试过了,它产生了500个错误。我的Apache版本是2.2.17它工作了!!!!非常感谢兄弟:)你能告诉我在
mod_rewrite
之前运行的
Apache的内容协商模块使用的
MultiViews
(请参阅)选项有什么不同,它使Apache服务器匹配文件扩展名。因此,如果
/index
是URL,那么Apache将提供
/index.php
。再次感谢:)谢谢怀特先生。选项+FollowSymLinks-多视图完成了这项工作,不客气<代码>多视图(mod_协商的一部分)是与mod_重写指令冲突的常见原因(当引用没有文件扩展名的文件时)。
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On