.htaccess rewrite rule not working for index.html

I have pretty urls enabled and have set my canonical url.
Putting canonical/index.php in browser gets rewritten to canonical/ which is fine. If i put canonical/index.html it does not get rewritten and I get a 404 page.

# -- concrete urls start --
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME}/index.html !-f
	RewriteCond %{REQUEST_FILENAME}/index.php !-f
	RewriteRule . index.php [L]
</IfModule>
# -- concrete urls end --

I have render only at canonical URLS set in concrete.
V9.3.7 on apache server (with nginx cache)

I tried in an online tester and the above code works.

any clues why this is happening?

That actually sounds correct to me.

The rewrite rule only kicks in if the index.html file doesn’t exists. If you have index.html, you’ll return that static page.

But in your case, you don’t have that file, so it’s going to fall to the final RewriteRule, which puts the request through Concrete. And Concrete isn’t going to find a page that has a slug of index.html, so returns a 404 response.

What are you expecting to happen?

I see.

I just want the url to go to canonical for /index.html

also I want to ensure search engines only find the canonical domain and not /index.php to prevent duplicate content. So I am trying to have the correct rules in my .htaccess to prevent that.

I think you would do something like add in

RewriteRule ^index\.html$ /$1 [R=301,L]

Directly under the RewriteBase /

In other words, you want to specifically say to redirect a request to /index.html to go just to the root.

Thanks Ryan

I had seen something like that elsewhere. Not being an expert I wanted to check within the Concrete community. I will try your suggestion.

Cheers

I have tried inserting

RewriteRule ^index\.html$ /$1 [R=301,L]

Directly under the RewriteBase /

it does work for /index.html but /index.php does not go to /
Do i need remove or add anything below?

If I add another line like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ /$1 [R=301]
RewriteRule ^index\.php$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]

That works but then I can’t get into the cms as /login redirects to /

so back to square one.

This isn’t something I’m that strong with, but could try:

RewriteEngine On
RewriteBase /

# Redirect /index.html to /
RewriteRule ^index\.html$ / [R=301,L] 

# Redirect /index.php to /
RewriteRule ^index\.php$ / [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]

This could work for you to just remove the index.html

RewriteEngine On
RewriteBase /
RewriteRule (.*)index\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]

This was similar to my attempt above but still could not access login. but thank you

RewriteEngine On
RewriteBase /
RewriteRule (.*)index\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]

This works for index.html and I can still get to the login interface. Thank you.

From what I can see its not possible to make index.php go to / without breaking the cms interface. So in respect of google seeing duplicate urls for index.php and / I think its best to let link rel=“canonical” tell Google which is the url to choose.