Loredra L
Loredra L

Reputation: 1553

HTML always loaded from cache

I have a index file under www/ and apache config set DirectoryIndex to that index.html

If I use this link

example.com/

Everything works fine since the html itself has meta tag to not use cache but if I use

example.com (Which in url bar will redirect to example.com/)
//Note: In chrome, the initiator for this also change to example.com

The index is always fetched from cache

And the second way is how normal end user type in the address. Can you guys explain what is going on?

Upvotes: 0

Views: 47

Answers (1)

Obsidian Age
Obsidian Age

Reputation: 42384

example.com/ is treated differently than example.com. The slash indicates that a URL is a folder and not a document. Adding extra slashes (such as example.com///) will also consititute an independent caching in this regard.

I would recommend forcing a single trailing slash, which can be done with the following .htaccess:

RewriteEngine On

# Assuming you're running at domain root.  Change to working directory if needed.
RewriteBase /

# www check
# If you're running in a subdirectory, then you'll need to add that in
# to the redirected url (http://www.example.com/subdirectory/$1

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

# Trailing slash check

# Don't fix direct file links
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Finally, forward everything to your front-controller (index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]

More information regarding this can be found here.

Hope this helps! :)

Upvotes: 1

Related Questions