I am hosting multiple sites on the same server and using a http-vhosts file to specify virtual host info for them. It is working great. The problem is I changed in Movable Type the way entries are created. I want them to not have file extension. So it is currently domain.com/entry/15 instead of domain.com/entry/15.html. Because I took out the .html I'm assuming apache doesn't know what to do so it is spitting out the page as plain text. How can I fix this? I added in a virtualhost block:
DefaultType text/html
I also added that in the httpd.conf hoping it would fix it globally for all my sites. I restarted apache and still the same problem. Any ideas?
Is it possible that this is a content negotiation problem? In a few cases I've seen Apache try to determine what sort of file is being requested by looking at the first few bytes of the file being served.
I have seen problems like this be solved by commenting out mod_negotiation in http.conf and restarting. See the mod_negotiation documentation for more details.
I just solved the same issue by disbabling Magic Mime in httpd.conf (some files would display as html and some as text for no apparent reason).
edit /etc/httpd/conf/httpd.conf
Comment the lines for the Mime Magic Module:
MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
Restart Apache and clear your browser cache
source
That seems correct. Care to share one link, or the HTTP headers that are returned for one of those pages? P.S. as well as the whole Apache config block where you placed that directive, for context?
if u create a .htaccess in ur site's root dir,and the .htaccess's content is:
DefaultType text/html
then the issue is fixed imm.
Related
In my HTML file there are several <img src="images/<filename>.jpeg">
The directory "images" holds these files:
<filename>.jpeg
as well as
<filename>.webp
and
<filename>.jpeg.webp
The latter two are identical webp versions of the jpeg file.
Now I want to configure Apache 2.4 on Oracle Linux 8.6 for 'content negotiation'. I am expecting that Apache returns a .webp file instead of the requested .jpeg file, if the browser supports .webp. I don't want to use the HTML <picture> tag or 'srcset' for several reasons, but leave the code untouched.
I have found several promissing configuration examples for nginx, but unfortunatly only litte on Apache:
https://gist.github.com/sergejmueller/5500879
https://stackoverflow.com/a/58857260/4335480
These two links outline 'rewrites' that are to go to the .htaccess file in the /images directory. I tried them both as '.htaccess' in the 'image' directory and it didn't work. I also put them directly in the httpd.conf and it didn't work either. And I tried these lines in the root directory's .htaccess
'AllowOverride All' is included in all section. Even the 'images' directory is explicitly listed.
In Chrome Dev Tools I verified that the request headers include 'image/webp'.
Probably not necessary: In my despair I have disabled nosniff on the Apache server and verified in the response header that it isn't set.
Whatever I try, the server only returns the jpeg file. I can verify this not only by the file name but also by the content-length field in the response header.
So what can I do to have Apache serve avif, webp and (fall back) jpeg in that order, whenever a jpeg file is requested?
Found the error myself. Note to self: don't just copy code snippets to use them. Read and understand them to find errors or identify necessary adaptions.
Vincent Orback's code is often cited for this problem, so I blindly trusted and used it: https://github.com/vincentorback/WebP-images-with-htaccess
It contains the following line:
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
The outcome is that .webp images are only searched for in the web server root directory. On my site, images are in a subdirectory called 'images'.
Trying to load an image in the browser would fail (deliver the jpeg, not the webp version):
https://<my domain>/images/<image name>.jpeg
But after altering above line to
RewriteCond %{DOCUMENT_ROOT}/images/$1.webp -f
eventually everything worked!
All the other things were unnecessary. You only need one AllowOverride All before the virtual host containers for <Directory / > and all servers and subdirectories would have .htaccess enabled, if present. For this problem, only one .htaccess in the image subdir was necessary, none in the root and no special httpd.conf entries. I turned nosniff on again. The alternativ .webp files just need the extention .webp, not .jpeg.webp
What settings do I need to set in order to make Apache serve SVGs?
What I found:
These questions document the use of .htaccess to serve the SVGs with the correct MIME type "image/svg+xml" SVG images not displaying on certain web servers / https://mid.as/kb/00134/configuring-server-to-handle-svg-images / https://davidwalsh.name/serve-svg-image
This question handles the Requested URL not found
None of these helped resolve this issue.
Files:
.htaccess:
AllowOverride All
RewriteEngine on
AddType image/svg+xml svg
Folder structure:
Result:
Other:
Different files like .png work. I also tested it with Node (npx http-server) which worked.
AFAICR any recent version of Apache should have the SVG MIME type already configured. You shouldn't have to do it yourself unless you are running a very old version.
Anyway, a misconfigured MIME type wouldn't casue a 404. I think something else must be going on.
If you haven't already, try looking at the Network tab in your browser dev tools, and the Apache access log to check whether you are actually fetching the URL you think you are. And check that the file permissions are set correctly. Does the file have the correct owner, group, and permissions to be accessed by apache?
Apache 2.4 includes mod_proxy_html and that's great, it's catching all kinds of URLs inside the HTML coming back from the server and fixing them. But I've got a Seam app that sends back text/xml files to the client sometimes with fully qualified URLs that also need to be rewritten and mod_proxy_html doesn't fix them.
Apparently there was a mod_proxy_xml that used to exist separately from mod_proxy_html but Apache didn't include that. Is there a way to get mod_proxy_html configured to do the same thing? I need it to fix URLs in both the HTML and XML files coming back from a server.
Follow up:
I continue to fight with this and I've tried a few different solutions with no success including using mod_substitute (which somehow I'm configuring incorrectly because it never seems to substitute anything for anything) and using the force flag mod_proxy_html has to try and force it to do all files under a certain path.
This is an old question, but I just faced the same issue.
I tried with mod_proxy_html, compiled mod_proxy_xml, nothing worked.
#JonLin's suggestion is spot on, it works with mod_sed.
The only if is mod_sed is documented to work inside Directory nodes.
If you declare a Location though and do a SetOutputFilter instead of AddOutputFilter (which requires a mime type) it works beautifully.
The config that works is:
<Location "/">
SetOutputFilter Sed
OutputSed "s,http://internal:80,https://external.com,g"
</Location>
I have been trying to get some url rewrites to work with .htaccess after moving a site to a new host.
Nothing seemed to work, so in frustration I removed all the code from the file, uploading a blank .htaccess file to the server. The Result: FORBIDDEN.
Is this a problem with the server config? How do I go about addressing it.
EDIT
Ok, so I got it to work. I think it must have had something to do with the encoding or format (or whatever) of the .htaccess file itself. I origionally suspected something like this and messed with a bunch of stuff in notepad++, and thought I ruled that out. Earlier, in desperation, I recreated the file in regular notepad and it worked.
Thank you all for your insights...
I don't think that being empty of not will make the difference. IMHO this is happening because the virtualhost is not allowing you to override in your document root
try adding this
<Directory "/var/www/example.com">
AllowOverride All
Allow from All
</Directory>
where /var/www/example.com is the path to your document root
I don't know if it can be related but have you insured that you have an index page (like index.html or similar) and in your <Directory> tag of your Apache's configuration file have the directive Options All -Indexes?
Have you tried with this options?
I'm trying to host a python script using an apache web server, but the server tries to run the script instead of just offering it for download.
I do not have direct access to server, and adding the line
AddType text/plain .py
to .htaccess in the root folder does not appear to work, though I could be doing something wrong.
How do I get the server to just send the file as text instead of trying to run it?
-Edit
Changing the name does not work. Script.py.safe still give a 500 Server error when you click it.
I should also mention that the .htaccess file does work, but for some reason that one addType line is not working. Either because it's not overriding something, or the line is wrong.
In your .htaccess:
RemoveHandler .py
If you can't change the Apache config and you can't override it with an htaccess file, then it seems to me that the easiest solutions would be either to change the file extension, or else to write a script that prints the contents of the target script.
Both are hacks to some extent, but the correct solution is to change the Apache config.
One option is to change the extention and make clear that it should be renamed. IE python.py.safe or python.py.dl. The user would then need to remove the extra bit.
You could also Zip it up.
I would write something that loads the python script up. This way you could even get energetic and include formatting and styling of the code. You could even write it in python since you will not have precluded that by file extension.
<IfModule mime_module>
<Files *.py>
ForceType text/plain
</Files>
</IfModule>
in a .htaccess for the folder should work ;)