LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-09-2020, 07:43 AM   #1
jag1
LQ Newbie
 
Registered: Nov 2019
Posts: 3

Rep: Reputation: Disabled
hiding file extension with htacces gives Internal Server Error?


Hello,

I get
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
on every single image, js file and css file. How can i fix this issue?


Options -MultiViews
RewriteEngine On

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,NE,L]

RewriteRule ^knowledge-center/(\d+)(?:/.*)?$ knowledge-center-desc.php?id=$1 [QSA,L,NC]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

ServerSignature Off


DirectoryIndex schedule.php

Last edited by jag1; 04-09-2020 at 07:47 AM.
 
Old 08-03-2020, 10:28 AM   #2
DocRoot
LQ Newbie
 
Registered: Aug 2020
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by jag1 View Post
RewriteRule ^knowledge-center/(\d+)(?:/.*)?$ knowledge-center-desc.php?id=$1 [QSA,L,NC]
You don't state what the URLs are that are being requested (for the images, CSS and JS files). However, the above rewrite would also catch images, CSS and JS files if they are of the form "/knowledge-center/123/image.jpg" etc. And these would all be rewritten to "knowledge-center-desc.php" - although this would probably just result in a bunch of 404s, not a 500.

Quote:
Originally Posted by jag1 View Post
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
However, this could result in a rewrite-loop (500 error) depending on the URL being requested, since the file check (2nd condition) is not necessarily the same as the URL being rewritten to. The first condition (that checks whether the request maps to a directory) is most probably superfluous. You should change this to:

Code:
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
You could also exclude (at the top of the file) all requests that look like images, CSS or JS files from being rewritten - this would be a good optimisation anyway. For example, add the following at the top of the .htaccess file, immediately after the RewriteEngine directive:

Code:
# Ignore any requests that contain an image, css or js file extension
RewriteRule \.(jpg|png|gif|css|js)$ - [L]
This then prevents images, css and js files from being processed any further - which should also prevent these resources from triggering a rewrite loop (most probable cause of the 500 error).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Htacces rule Sajil143 Linux - Server 3 02-10-2018 01:27 PM
[SOLVED] 505- Internal server error - The server encountered an internal error or misconfigura physnastr Linux - Server 7 11-17-2011 04:57 PM
[SOLVED] Apache not reading .htacces on 443 MasterMatt Linux - Newbie 4 05-05-2011 02:30 AM
Apache: trouble with .htacces dowski Linux - Software 9 05-17-2004 11:58 PM
apache .htacces LabRad Linux - Software 2 08-04-2003 04:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration