我使用名为SilverStripe的框架......我们目前正在将旧网站迁移到此框架中。问题在于旧网站的网址以.php或.html结尾,而在新网站中却没有。.htaccess重定向.php和.html请求
我需要修改第二个重写规则,以便将请求传送到main.php而不带任何.html或.php扩展名。
在我目前的.htaccess我有以下规则:
# Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
<IfModule mod_dir.c>
DirectoryIndex disabled
</IfModule>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
# Enable HTTP Basic authentication workaround for PHP running in CGI mode
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]
# If framework isn't in a subdirectory, rewrite to installer
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
可能的解决方法(仍在测试):
RewriteCond %{REQUEST_URI} ^(.*)\.html [OR]
RewriteCond %{REQUEST_URI} ^(.*)\.php [OR]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]
@ 3dogo不幸的是规则没有触发 –
这很奇怪。它适用于我的测试。例如,如果我访问“www.example.com/about.html”,它将重定向到“www.example.com/about”。另一个例子“www.example.com/about/team.php”将重定向到“www.example.com/about/team”。 – 3dgoo
你用什么版本的Apache进行测试? –