Hope someone can help. Apologies for not being well informed on htaccess. I have tried to search and spent a few hours on various options but no success.
I’m using a CMS where basic URLs are in the form domain.com/index.php/page-name
There is an admin setting to lose the index.php and just have domain.com/page-name, which creates the htaccess entry below:
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv gp_rewrite gJjsF6q
</IfModule>
RewriteEngine On
RewriteBase "/"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_cache.c>
RewriteRule /?(.*) "/index.php/$1" [L]
</IfModule>
<IfModule !mod_cache.c>
RewriteRule . "/index.php" [L]
</IfModule>
</IfModule>
To take care of core canonicalisation, have been attempting to redirect any request for non www URLs to www and so far failed. Almost everything produces a server error of some sort, a 500, or, The document has moved here – Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
By tacking the www/non www rewrite at the end (as below) at least the domain functions but the redirection only works for the root. Every other page then ignores the /index.php/ rewrite and returns pages in the format domain.com/index.php/page-name again.
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv gp_rewrite gJjsF6q
</IfModule>
RewriteEngine On
RewriteBase "/"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_cache.c>
RewriteRule /?(.*) "/index.php/$1" [L]
</IfModule>
<IfModule !mod_cache.c>
RewriteRule . "/index.php" [L]
</IfModule>
<Ifmodule mod_rewrite.c>
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
</Ifmodule>
</IfModule>
Essentially worse than no redirect. If anyone has suggestions how the core CMS needs can be maintained and the www/non www solved, they would be very welcome.
You need to put the redirect rules above the rest of your rules and include a
Lflag: