Eric
Eric

Reputation: 429

Adding a forward slash to the end of my URLs is breaking them

I would like to add a forward slash to the end of all my URL's....

Currently, an example link on my website is: <a href="/about/terms-of-use">

I'm getting an Internal Server Error when I change this to: <a href="/about/terms-of-use/">

Here is my htaccess:

AddType application/x-httpd-php .html 
AddType application/x-httpd-php .htm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html  [L]

Why would the trailing forward slash be breaking the URL's?

Upvotes: 0

Views: 1034

Answers (1)

Tom Knapen
Tom Knapen

Reputation: 2277

The rule is breaking because (for your example) you get something like: terms-of-use/.html Try this instead:

AddType application/x-httpd-php .html 
AddType application/x-httpd-php .htm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ $1.html  [L]

This will remove the last slash from the request, and then rewrite it to the appropriate file.

Upvotes: 1

Related Questions