I'm having really difficult time with my .htaccess file - apache

I'm having really difficult time with my .htaccess file
(Apache) httpd.conf: The following are uncommented:
mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
My document root / directory:
DocumentRoot "f:/www"
<Directory "f:/www">
My index.html file is in:
F:\www\portfolio2
My .htaccess file is in:
F:\www\portfolio2
Inside my .htaccess file:
RewriteEngine on
RewriteRule ^portf/([0-9a-zA-Z]+) index.html?p=$1 [NC,L]
The directory:
F:\www\portfolio2\portf
does not exist, but I'm pretty sure it doesn't need to, right?
Inside my index.html :
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/portfolio.css" rel="stylesheet">
<script src="jquery/jquery-3.2.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="js/javascript.js"></script>
When I test the url:
http://localhost/portfolio2/portf/qweasd
My console logs the following errors / warnings:
Uncaught SyntaxError: Unexpected token < jquery-3.2.1.min.js:1
Uncaught SyntaxError: Unexpected token < bootstrap.min.js:1
Uncaught SyntaxError: Unexpected token < javascript.js:1
Resource interpreted as Stylesheet but transferred with MIME type text/html:
"http://localhost/portfolio2/portf/bootstrap/css/bootstrap.min.css".
qweasd:20
Resource interpreted as Stylesheet but transferred with MIME type text/html:
"http://localhost/portfolio2/portf/css/portfolio.css".
qweasd:21
From What I see, it thinks I have a directory named "portf", which I don't.
Am I doing something wrong?
EDIT: I forgot to mention, the page loads but not the CSS, JavaScript, etc.
EDIT2: Solved. I added: RewriteBase /portfolio2/ to .htaccess and I'm using relative URL's throughout my site. I also replaced rel="stylesheet" and the styles are now being applied. Then I added <base href="/portfolio2/">
in <head> before CSS and JavaScript imports. Cheers!

Related

https redirect with Apache is returning a blank page

I have a WAMP installation running on a Raspberry pi 3. Apache v2.4.33, php 7.2.4.
I want the default url address of my site - "//www.quintic.co.uk/" - to actually address "//www.quintic.co.uk/index.php?home". So I added the following to the .htaccess file:
DirectoryIndex index.php?home
I have also configured Apache to always use https protocol, by updating the apache config file with the following:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}/$1 [END,NE,R=permanent]
For the most part, all the above seems to be working perfectly. For example, if I request http://www.quintic.co.uk/ then I am redirected to https://www.quintic.co.uk/index.php?home.
All http requests are switched correctly to https requests.
All https requests are returning correctly, with the exception of https://www.quintic.co.uk/, which returns a blank page.
The actual instruction set returned from a https://www.quintic.co.uk/ request is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-eqiv="refresh" content="0" url="https://www.quintic.co.uk/index.php?home" />
<script type="text/javascript" src="https://ff.kis.v2.scr.kaspersky-labs.com/E989763D-7B5C-014A-B514-22905C3EEE53/main.js" charset="UTF-8"></script></head>
<body>
</body>
<!-- End of #container-->
<!--Scripts after page loads-->
</html>
If I cut & paste the url in the meta statement into a browser, the home page is returned fine.
Can anyone shed some light on why the default url redirect is not working with https.
Thanks
SteveD430
The problem was in the apache2.conf. Within the Quintic site 'Directory' element. I had the following:
AllowOverride None
Order allow,deny
allow from all
Require all granted
It needed to be
AllowOverride All
Site is now working perfectly.

Running AngularDart on Apache

My Angular Dart site runs fine with pub serve. I would prefer to run it with Apache. When I enter the url jazzcat.loc/index.html I get the following browser errors:
GET http://jazzcat.loc/packages/browser/dart.js index.html:22
GET http://jazzcat.loc/packages/polymer/polymer.dart package:polymer/polymer.dart:1
An error occurred loading file: package:polymer/polymer.dart index.html:22
GET http://jazzcat.loc/packages/angular2/platform/browser.dart package:angular2/platform/browser.dart:1
An error occurred loading file: package:angular2/platform/browser.dart
index.html:22 GET http://jazzcat.loc/packages/jazzcat/app_component.dart package:jazzcat/app_component.dart:1
An error occurred loading file: package:jazzcat/app_component.dart favicon.ico:1
GET http://jazzcat.loc/favicon.ico 404 (Not Found)
The virtual host entry for the site is:
<VirtualHost *:80>
ServerName jazzcat.loc
DocumentRoot /Volumes/Data/htdocs/jazzcat/web
<directory /Volumes/Data/htdocs/jazzcat/web>
Allow from all
Options -MultiViews
Require all granted
</directory>
</VirtualHost>
There is no .htaccess file
This is index.html:
<!DOCTYPE html>
<html>
<head>
<title>Jazz Cat</title>
<script>
window.Polymer = window.Polymer || {};
window.Polymer.dom = 'shadow';
</script>
<!-- For testing using pub serve directly use: -->
<base href="/">
<!-- For testing in WebStorm use: -->
<!-- base href="/dart/web/" -->
<link href="master.css" rel="stylesheet" type="text/css" />
<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>
</head>
<my-app>Loading...</my-app>
</html>
I also tried using
<base href="/dart/web/">
It also errors out. I'm testing in the Chromium browser.
I've seen questions and answers here about routing. They seem to apply to routing beyond index.html.
AFAIK pub serve is meant to be used during development, if you want to use apache to serve your app, you might need to use pub build to transform (and optimize) your app to a regular html+javascript app, here you might find more information.

.htaccess RewriteRule works but my css doesnt work in that page

.htaccess file code
RewriteEngine On
RewriteRule ^book/([a-zA-Z0-9_-]+)$ book.php?isbn=$1
RewriteRule ^book/([a-zA-Z0-9_-]+)/$ book.php?isbn=$1
It works but the css files, images files, JS files linked with it doesn't work. The Page come without any css formatting. The url to my website is given below please help
Link to My Page using this
I want that an address which is like "www.booksiders.com/book.php?isbn=9780545010221" to appear like "www.booksiders.com/book/9780545010221"
and this is working but somehow the linked files are not working.
You have problem not with rewrite rules.
Change
<link rel="stylesheet" type="text/css" href="css/any.css" />
to
<link rel="stylesheet" type="text/css" href="/css/any.css" />
because browser think that he has to load book/css/any.css, but must load /css/any.css

What HTTP header indicates when Index.html has been served?

Excuse the awkward title: I'm building a simple web server (don't ask...) and have this problem:
The browser requests mydomain.com/MyFolder
My server spots this is a folder, so instead, delivers mydomain.com/MyFolder/index.html
All fine so far, except that index.html has link to mycss.css, but the browser requests it as a top-level file mydomain.com/mycss.css instead of mydomain.com/myFolder/mycss.css.
Is there some HTTP header that needs setting up to indicate that a different page has been served? I've tried returning Content-Location: /myFolder/index.html, but without any visible success.
index.html basically contains this:
<link rel="stylesheet" href="mycss.css" />
Return a 301 Moved Permanently status code, instead of the 200.
Provide a Location header pointing to the same url plus a slash in the end /
Like so:
Location: mydomain.com/MyFolder/
Do not serve the index.html file on that same request, wait for the browser to request again with the slash at the end.
Or just try to add something like this to your .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)$ myFolder/$1
Can you just try to change this:
<link rel="stylesheet" href="mycss.css" />
to this:
<link rel="stylesheet" href="/myFolder/mycss.css" />
?
Ok, actually the information given was not correct so I'm modifying the answer. If you are implementing a web-server, you must follow the standard specification. The definition <link rel="stylesheet" href="mycss.css" /> shall retrieve the the CSS file from the same location as the file in which it is defined in (index.html) is. When using relative paths, it is not the browser that requests from a specific location but the web-server should determine the location from which to serve the resource.
Check section 2.4.6 and 3 in the standards document: http://www.ietf.org/rfc/rfc1808.txt
In other words, if the path of a resource does not start with the slash (/), it is considered as relative and should be located relative to the base URL.

Favicon for all the pages in my website

I've learned that the way to add favicon for a web page is to have the following lines in the page.
<link rel="SHORTCUT ICON" type="image/x-icon" href="http://mysite.com/faviconfilename.ico"/>
<link rel="icon" type="image/x-icon" href="http://mysite.com/faviconfilename.ico" />
Should i add this code in each and every page my site has?? I use Apache - tomcat clustering to serve pages. Is there any other easy way to do this?
It is usually enough to place a file called "favicon.ico" in the root of your website.
You can get rid of the unnecessary processing and traffic as well as the error log entries by using the following Apache configuration incantations:
# Don't bother looking for favicon.ico
Redirect 404 /favicon.ico
# Send custom text instead of sending the custom error page
<Location /favicon.ico>
ErrorDocument 404 "No favicon"
</Location>
Modify the apache config.
upload this file to the root directory of your website. Make sure that it is readable so that apache can read it. If you have shell access, type: "chmod +r favicon.ico".
Then edit httpd.conf and insert the following line:
"AddType image/x-icon .ico"
Your approach works when you don't have access to your apache config. In this case, if you are using any framework then you should add it to your layout/template.
Here is my method for php sites. It ensures that if you update the favicon, it will be updated immediatly when your clients visit your site:
<link rel="shortcut icon" href="favicon.ico?v=<?php echo time() ?>" />