htaccess MIME type css read as text/html - html

Before you reference similar questions: I did actually do research yet no post solved my issue.
I literally have the most basic code you can imagine yet one of the most basic things won't work. The CSS file is interpreted as text/html while I need it to be a read as a stylesheet. This is due to my .htaccess file even though I explicitly added the AddType thing.
Here's my HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>EASY-Online</title>
<link href="./css/bootstrap.min.css" type="text/css"/>
</head>
<body>
<div class="alert alert-warning">
test
</div>
</body>
</html>
My htaccess:
RewriteEngine On
RewriteBase /
AddType text/css .css
RewriteCond %(REQUEST_FILENAME} !-d
RewriteCond %(REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,T=text/css]

After some more research I found this to fix my issue:
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
I added this directly above the RewriteRule. Apparently this allows the described
extentions to be reachable by navigating to them instead of redirecting.

RewriteCond %(REQUEST_FILENAME} !-d
RewriteCond %(REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_FILENAME} !-l
->(<- ERROR in line 1,2 and 3 in character 13
try this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

Related

Apache how to redirect to other port?

On a rpi with Apache i want to redirect port 80 to port 6830.
index.html;
<! -- Redirect to port -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 15 - http://www.wysiwygwebbuilder.com">
<meta http-equiv="refresh" content="0; URL=:6830">
</head>
<body>
<div id="wb_Heading1" style="position:absolute;left:46px;top:19px;width:522px;height:69px;z-index:0;">
<h1 id="Heading1">Untitled Page</h1></div>
</body>
</html>
Gives http://192.168.178.99/:6830
How can I remove / from the link
You can use rewrite rules to redirect them, make sure mod_rewrite is enabled in your apache, add it to .htaccess or httpd.conf :
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ http://%{HTTP_HOST}:6830%{REQUEST_URI} [R=301,L]
If you only want to redirect index.php, use this:
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^\/index.php$
RewriteRule ^.*$ http://%{HTTP_HOST}:6830%{REQUEST_URI} [R=301,L]
Let me know if it doesn't work :)

How to hide file extension(html)?

i had tried to hide the file extension using htaccess but failed.
this is the code on my .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\ (INSERT FILE EXTENSION) -f
RewriteRule ^(.*)$ $1 (INSERT FILE EXTENSION)
and in my html file the code is :
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
</head>
<body>
<h1>This is profile</h1>
</body>
</html>
when i accessing the webpage without the extension i got this error

Removing .html using htaccess

I'm quite new to html and I want to remove the .html , i did some research and figured out i have to edit the .htaccess.
now i have this code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
But when i go to www.mywebsite.com/about it shows the html text (from the html file) in my webpage.
What i see is like this: <DOCTYPEHTML!>
<head>
<title>BETA-About me</title>
<meta charset="utf-8">
etc.
How can i use the .htacces to remove the .html part without showing plain html text?

Redirect website after 5 seconds and match path

How to create a HTML redirect after 5 secconds and match same path
Example:
Redirect: www.oldsite.com/post123 to www.newsite/post123
i have tried this code but it only redirects to my home page
<html>
<head>
<meta http-equiv="refresh" content="3;url=http://www.somewhere.com/" />
</head>
<body>
<h1>Redirecting in 3 seconds...</h1>
</body>
right now im using an htaacess to do that with is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^.*bberryblog.com$
RewriteRule ^$ http://unionmovil.com/category/blackberry [R=301,L]
RewriteCond %{HTTP_HOST} !(www).unionmovil.com
RewriteRule ^(.*)$ http://www.unionmovil.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
but i want to perform that via html so it will be after 5 secconds the redirect
If you're using javascript you can write a function like:
var myVar=setInterval(function () {myTimer()}, 3000);
function myTimer() {
window.location="www.newsite/post123"
}
Here with the set interval function you tell it to run a function every given seconds, which we set to 3 Seconds (3000). Then we direct the window to a new location within the function

css not displaying with absolute paths after .htaccess re_writes

I'm faced with the problem of CSS not being displayed after using the mod_rewrite in .htaccess, heres the problem:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^css/(.*)$ Templates/Testing/html/css/$1 [QSA]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
CSS is located in:
Templates/{TemplateName}/html/css/
TemplateName in this case being Testing.. But on my view source, it's just an infiniate loop to whatever I have in my
<link href="" rel="stylesheet" type="text/css" />
I've tried making virtual directorys to remap a virtual directory to a physical directory, but this has no luck!
Try adding L flag in both the rules:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(css/.+)$ Templates/Testing/html/$1 [NC,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]