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.
Related
Our website is targeting several languages and countries. We make the choice to use subdomain to manage our URLs. We want to avoid to create duplicate content and canonical issues.The content for www. and en. is identical but we plan to adapt the content for en. (in order to target UK).
For main domain, google is understanding:
<link href="https://www.example.com/" hreflang="en" rel="canonical" data-trid="15">
<link href="https://example.com/" hreflang="x-default" rel="alternate" data-trid="16">
<link href="https://example.com/" hreflang="en" rel="alternate" data-trid="17">
<link href="https://en.example.com/" hreflang="en-gb" rel="alternate" data-trid="18">
<link href="https://fr.example.com/" hreflang="fr" rel="alternate" data-trid="19">
<link href="https://de.example.com/" hreflang="de" rel="alternate" data-trid="20">
For english subdomain:
<link href="https://en.example.com/" hreflang="en-gb" rel="canonical">
<link href="https://example.com/" hreflang="x-default" rel="alternate">
<link href="https://example.com/" hreflang="en" rel="alternate">
<link href="https://en.example.com/" hreflang="en-gb" rel="alternate">
<link href="https://fr.example.com/" hreflang="fr" rel="alternate">
<link href="https://de.example.com/" hreflang="de" rel="alternate">
What is the best practice to avoid any canonical & duplicate content issues?
Thanks for your help!
Common Mistakes
Important: Make sure that your provided hreflang value is actually valid. Take special care in regard to the two most common mistakes:
Missing confirmation links: If page A links to page B, page B must link back to page A. If this is not the case for all pages that use hreflang annotations, those annotations may be ignored or not interpreted correctly.
Incorrect language codes: Make sure that all language codes you use identify the language (in ISO 639-1 format) and optionally the region (in ISO 3166-1 Alpha 2 format) of an alternate URL. Specifying the region alone is not valid. Via / Read:
https://support.google.com/webmasters/answer/189077?hl=en
The best way to avoid duplicates is to create a unique content for each version, if you can't add content now you have to block these pages or sub-domains by robots.txt or by adding a canonical link to the original page which is en.example.com in your case.
when you have content for each version, remove all these changes and make google able to index them.
.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
"Mixed Content: The page at 'https://mywebsite/user/signin?ReturnUrl=%2f' was loaded over HTTPS, but requested an insecure stylesheet 'http://fonts.googleapis.com/css?family=Raleway:300,200,100'. This request has been blocked; the content must be served over HTTPS."
In my head tag I have these links,
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,400italic,700,800' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:100' rel='stylesheet' type='text/css'>
Rather than making them https, is there a solution to determine http or https and dynamically change these links?, sounds like a very simple question.
Well, surprisingly the answer found to be a pretty simple one, just remove http
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600,400italic,700,800' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Raleway:100' rel='stylesheet' type='text/css'>
I've found some conflicting information regarding SSL and links of external sources. In one web source, the writer says that all external resources should be explicitly made as https. His solution would be to use "//" (an https connection of the url would lead to an https connection of the resource) as in:
<link rel="stylesheet" type="text/css" media="all" href="//css/styles.css" />
On another page, I saw that as long as the external resource is coming from your domain, it won't be an issue. So for example,
<link rel="stylesheet" type="text/css" media="all" href="/css/styles.css" />
or
(more explicitly)
<link rel="stylesheet" type="text/css" media="all" href="https://www.mycoolwebsite.com/css/styles.css" />
would both work.
I've tested my https connection in Firefox using
<link rel="stylesheet" type="text/css" media="all" href="/css/styles.css" />
and it worked fine, but it also seems that SSL may not work on all browsers, so I'm not convinced that my 1 browser check is indicative of a solution that will work wherever SSL works.
Which would be the best approach for my external css/javascript files that reside on my own domain?
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>