[英]RewriteRule on apache2
I have a problem with the Rewrite
rules. 我对Rewrite
规则有Rewrite
。 I'd like to redirect domain.xx/example
to domain.xx/index.php?content=example
我想将domain.xx/example
重定向到domain.xx/index.php?content=example
This would actually work, but I also have a file named example.php in the same folder ( domain.xx/example.php
). 这实际上可以工作,但是我在同一文件夹( domain.xx/example.php
)中也有一个名为example.php的文件。 Whenever I open domain.xx/example
, the server opens example.php
instead of redirecting me to index.php?content=example
. 每当我打开domain.xx/example
,服务器就会打开example.php
而不是将我重定向到index.php?content=example
。
The mod-rewrite
is on and works fine when I delete the example.php
file. 当我删除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]
That is because of MultiViews
option. 那是因为有MultiViews
选项。
Add this line on top of your .htaccess: 将此行添加到.htaccess的顶部:
Options -MultiViews
add this to your htaccess file: 将此添加到您的htaccess文件中:
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
so the example.php will be served directly, then add your rule. 因此example.php将直接提供,然后添加您的规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.