RewriteRule ^/colleges/([A-Za-z0-9-.']+)/([0-9-]+)/?$ /ShowMasterdashboard.do?cn=$1&institutionId=$2 [PT,NC,L]
server attempt to load css and js from colleges/css/.css and colleges/js/.js,so page look ugly
Try adding a forward slash before script/css location:
<script src="/custom.js" type="text/javascript"></script>
instead of
<script src="custom.js" type="text/javascript"></script>
Related
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!
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 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
I am a newbie for rewriting url, I have rewritten my url, but it is causing problem for all the relative paths used in the page like
<link href="style/style.css" rel="stylesheet">
<link href="images/icon.png" type="images/ico" rel="icon" />
<img src="images/test.png" id="test">
Even i have applied the following rewrite rule for them, but still i find 404 error in firebug console (first one is working but second is not working for relatvie)
RewriteEngine On
RewriteRule ^raipur/([A-Za-z0-9-]+)/([0-9]+)$ /viewRestaurant.php?raipur=$1&id=$2
RewriteRule ^raipur/([A-Za-z0-9-]+)/([A-za-z]+)/ /$2/
my console screenshot
I had even debugged my rewrite rule into htaccess tester and its working there as required
You links are all relative links. "images/icon.png" instead of "/images/icon.png". Because your url changed its URL base from:
/viewRestuarant.php
Base: /
to
/raipur/something/1234
Base: /raipur/something/
When the browser sees a link like: images/icon.png it needs to prepend a base URL to it in order to know where the resource is located. By default it uses the host and base based off of the URL that it sees in the location bar. Since that's obviously not where any of these resources are, you need to either make your links into absolute URL's like: /images/icon.png or http://example.com/images/icon.png or add an explicit relative URL base into the header of your pages (between the <head> </head> tags):
<base href="/" />
I'm making a project using iWebKit. I When I include the files, I don't want to have to keep linking back to the directory the framework is in like:
<link href="css/style.css" rel="stylesheet" media="screen" type="text/css">
<link href="../css/style.css" rel="stylesheet" media="screen" type="text/css">
<link href="../../css/style.css" rel="stylesheet" media="screen" type="text/css">
<link href="../../../css/style.css" rel="stylesheet" media="screen" type="text/css">
I want to be able to have the same directory in every other directory so localhost/css/style.css is the same as localhost/some/other/directory/css/style.css.
I am using Apache and want to know if there is a way to do this with .htaccess
Use absolute paths
<link href="/css/style.css" rel="stylesheet" media="screen" type="text/css">
Note the / in from of the path.
You can do this my using mod_rewrite
For this add the following to the .htaccess file in the root of your application
RewriteEngine On
RewriteRule ^.*/css/([^./]*)\.css$ /css/$1.css [L]
Here the Regular Expression ^.*/css/([^./]*)\.css$ matches any string with /css/any_name.css in the end, and rewrites the URL to point internally to css folder in the root. And [L] means it is the last rule to match if it matches. And $1 refers to the parenthesized portion of the Regular Expression that matches the URL, which is the name of the stylesheet
For more complex scenarios I would suggest you read up some more on the internet.