繁体   English   中英

apache2上的RewriteRule

[英]RewriteRule on apache2

我对Rewrite规则有Rewrite 我想将domain.xx/example重定向到domain.xx/index.php?content=example

这实际上可以工作,但是我在同一文件夹( domain.xx/example.php )中也有一个名为example.php的文件。 每当我打开domain.xx/example ,服务器就会打开example.php而不是将我重定向到index.php?content=example

当我删除example.php文件时, mod-rewrite处于打开状态,并且工作正常。

RewriteEngine On
RewriteBase /
RewriteRule ^example$ index.php?content=example [NC,L]

重写规则是正则表达式,因此您只需要删除结尾字符以匹配example和example.php

RewriteRule ^example index.php?content=example [NC,L]

那是因为有MultiViews选项。

将此行添加到.htaccess的顶部:

Options -MultiViews

将此添加到您的htaccess文件中:

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

因此example.php将直接提供,然后添加您的规则。

暂无
暂无

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

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