Ich arbeite mit einem Framework namens SilverStripe ... wir sind gerade dabei, eine alte Site auf dieses Framework zu migrieren. Das Problem ist, dass die alten Site-URLs mit .php oder .html enden, während sie in der neuen Site nicht sind..htaccess redirect .php und .html Anfragen
Ich muss die zweite Rewrite-Regel so anpassen, dass ich die Anfrage ohne irgendwelche .html oder .php Erweiterungen in die main.php pumpe.
In meiner aktuellen .htaccess habe ich die folgenden Regeln:
# 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]
Mögliche Lösung (noch testen):
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 leider die Regel nicht ausgelöst –
Das ist seltsam. Es funktioniert für mich mit meinen Tests. Wenn ich zum Beispiel "www.example.com/about.html" besuche, wird es auf "www.example.com/about" umgeleitet. Ein anderes Beispiel 'www.example.com/about/team.php' wird zu' www.example.com/about/team' umgeleitet. – 3dgoo
Mit welcher Version von Apache testen Sie? –