2

My .htaccess is set up to remove .html from URLs as follows:

RewriteEngine on
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

This is causing problems with the file /help.html, which now gives a 403 Forbidden error:

Forbidden

You don't have permission to access /help/.html on this server.

Additionally, a 404 Not Found error was encountered while 
trying to use an ErrorDocument to handle the request.

Is there a way to keep friendly URLs and make the help page work?

  • I've found one solution: to rename help.html to help.htm. That's what I'll do if there's no other way to do it. – Knocks X Apr 14 '15 at 0:15
  • Is there a reason why R=302 does not appear in [NC,L] in the last statement?? As well NC is not necessary for RewriteRule- just RewritCond. And you should have L in [R=301,NC] in the second line. – closetnoc Apr 14 '15 at 0:34
  • Thanks, I'll make the changes regarding NC, but why 302 if these redirects are permanent? – Knocks X Apr 14 '15 at 0:40
  • You still need the R which defaults to 301 but you can make it 302 if you want with R=302. – closetnoc Apr 14 '15 at 1:08
  • I understand, but that's not what's causing the problem with help.html--I'd like to fix that first. – Knocks X Apr 14 '15 at 1:16
1

Try this

RewriteEngine on
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /help 
 RewriteRule . - [L]
RewriteRule ^([^\]+)$ $1.html [NC,L]

I added a condition to your .htaccess to check if the Requested URI contains /help ,then it will be passed unchanged to its destination.

  • The error message is different now: "Forbidden You don't have permission to access /help/ on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request." – Knocks X Apr 14 '15 at 5:58
  • @Knocksx is this your complete .htaccess or there are other rules also? – starkeen Apr 14 '15 at 6:39
  • This is the full code – Knocks X Apr 14 '15 at 20:03
  • " You don't have permission to access /help/ " means it tries to open index.html or index.php and cant find it – Martijn Jul 13 '15 at 8:04
  • error page are in alias to be served for each virtual host, you need to exclude the errors pages from the rewrite Cond like RewriteCond %{REQUEST_URI} !404.htm then you need to set a default documentto serve a page when you access a path – Froggiz Nov 24 '15 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.