mod_rewrite中有相当多的内容可用,但我根本无法获得以下内容。处理htaccess中的尾部斜线
现在我有下面的代码在我的htaccess文件:
RewriteEngine On
Options -Indexes
Options -Multiviews
ErrorDocument 400 http://localhost/mywebsite/400.php
ErrorDocument 403 http://localhost/mywebsite/403.php
ErrorDocument 404 http://localhost/mywebsite/404.php
ErrorDocument 500 http://localhost/mywebsite/500.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
这将成功地使事情变得像mywebsite /检索工作(而不是mywebsite/index.php文件)。 但是,在某些情况下,我会让访问者以斜线(mywebsite/index /)访问站点,然后我的重写不再起作用。我收到一个错误页面。
那么我怎样才能让它工作,以便任何一个带有斜线,无斜杠或扩展名(.php)的页面都可以在我的网站上使用?
我会补充说这是在Apache服务器(XAMPP)上的localhost上,以防这会影响mod_rewrite的工作方式。
这使得两个网址都带有尾部斜杠并且没有任何故障(只有使用扩展后才能使用的网址) – bucketman
@Bucketman尝试更新后的版本,它可以在我的服务器上运行。 – starkeen
给了我一个404错误页面。它不起作用的事实让我怀疑我是否错过了apache服务器中的一个设置,这将是非常奇怪的,因为原始代码对任何事情都很好,除了尾部空格。 – bucketman