.htaccess 我需要你不能访问文件扩展名

.htaccess 我需要你不能访问文件扩展名,.htaccess,.htaccess,我的.htaccess文件: RewriteEngine On # If the request sent by the browser includes index.php... RewriteCond %{THE_REQUEST} index\.php # forbid access (403) RewriteRule ^. - [F] # Then you just need a generic rule to rewrite /mysite into index.php Rewrit

我的.htaccess文件:

RewriteEngine On

# If the request sent by the browser includes index.php...
RewriteCond %{THE_REQUEST} index\.php
# forbid access (403)
RewriteRule ^. - [F]

# Then you just need a generic rule to rewrite /mysite into index.php
RewriteRule ^mysite index.php [L]

我需要你不能访问:www.mysite.com/mysite.php,我只能访问:www.mysite.com/mysite。

在你的情况下,你只需要在
mysite
后面添加
$
。您已经阻止了对index.php的访问,但是您的第二条规则匹配了
mysite
,以及以
mysite
开头的任何其他url,包括
mysite.php
mysite/is/awesome.gif

RewriteEngine On

# If the request sent by the browser includes index.php...
RewriteCond %{THE_REQUEST} index\.php
# forbid access (403)
RewriteRule ^ - [F]

# Then you just need a generic rule to rewrite /mysite into index.php
RewriteRule ^mysite$ index.php [L]
请注意,您可以使用
RewriteRule^-
而不是
RewriteRule^-。后一个要求至少有1个字符,而第一个字符匹配所有字符,这在本例中不是问题,但当您尝试编写匹配所有字符的内容时,可能会咬到您