Bhavani Kannan
Bhavani Kannan

Reputation: 1279

URLs break when a html page is ending with a slash

I have a website say www.domain.com

It has a html page say at www.domain.com/page.html

It does not load when I add a / at the end as in

www.domain.com/page.html/

I think its because its trying to assume / as a folder and tries to see if there is anything inside the page.html folder.

So, how do I fix this? What needs to done to make all my .html files work fine even if:

  1. I add a / at the end of them
  2. I make it as just htm instead of html
  3. I make it as all upper or mixed case as in .HTML or .hTML etc

Any solution with best practices please?

The reason is to direct all the traffic to the correct relevant pages of my site.

Upvotes: 1

Views: 371

Answers (2)

anubhava
anubhava

Reputation: 785581

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} /$
RewriteRule ^(.+?)\.html?/?$ /$1.html [L,NC,R=302]

Upvotes: 1

Gamma
Gamma

Reputation: 331

Are you trying this with localhost and you're not able to see localhost/domainexample/page.html/ because of trailing slash? if yes then you better look for virtual host so your domain will look like live domain

Upvotes: 1

Related Questions