简体   繁体   English

.htaccess在Apache上的RewriteRule无法正常工作

[英].htaccess RewriteRule on apache not working

I've tried everything. 我已经尝试了一切。 The following .htaccess file seems to work wonders on my local XAMPP server: 以下.htaccess文件似乎在我的本地XAMPP服务器上运行奇妙:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule pilot/([^/]*)$ /pilot.php?name=$1
</IfModule>

But it sadly doesn't work when i upload it to my web-host. 但可悲的是,当我将其上传到网络主机时,它不起作用。 Any help or input would be appreciated. 任何帮助或投入,将不胜感激。

EDIT: I forgot to add that it does redirect to the file correctly, but the variable isn't grabbed for some odd reason. 编辑:我忘记添加它确实可以正确重定向到文件,但是由于某些奇怪的原因而没有捕获变量。 I've also tried this: 我也尝试过这个:

RewriteRule ^pilot/(.*)$ /pilot.php?name=$1

But it doesn't work either. 但这也不起作用。 I'm completely lost. 我完全迷路了。 My web-host is OVH. 我的虚拟主机是OVH。

EDIT2: I was at least able to narrow down the issue a little bit. EDIT2:我至少能够将问题缩小一点。 I've found that doing this: (note the - instead of the /) 我发现这样做:(请注意-而不是/)

RewriteRule ^pilot-(.*)$ pilot.php?name=$1

Works absolutely fine. 绝对正常。 There is something wrong with the slash, but i can't figure a way to fix it. 斜杠出了点问题,但我想不出办法解决。

EDIT3: Well, apparently EDIT3:好吧,显然

RewriteRule ^character/([a-zA-Z_]+)$ show.php?name=$1 [L] RewriteRule ^字符/([[a-zA-Z _] +)$ show.php?name = $ 1 [L]

works but 起作用但是

RewriteRule ^pilot/([a-zA-Z_]+)$ show.php?name=$1 [L] RewriteRule ^ pilot /([[a-zA-Z _] +)$ show.php?name = $ 1 [L]

doesn't. 没有。 Oh well.. 那好吧..

Try to add this in your htaccess: 尝试将其添加到您的htaccess中:

Options -MultiViews

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. MultiViews的作用如下:如果服务器收到对/ some / dir / foo的请求,如果/ some / dir启用了MultiViews,并且/ some / dir / foo不存在,则服务器将读取目录以查找名为foo。*的文件,并有效地伪造了一个类型图,该类型图对所有这些文件进行了命名,为它们分配了与客户端要求通过名称提供的相同的媒体类型和内容编码。 It then chooses the best match to the client's requirements. 然后,它选择最符合客户要求的匹配项。 http://httpd.apache.org/docs/2.2/en/content-negotiation.html http://httpd.apache.org/docs/2.2/en/content-negotiation.html

And after that work well with: 在此之后,可以使用:

RewriteRule pilot/([^/]*)$ /pilot.php?name=$1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM