Css and javascript not loading with rewrite condition? [duplicate] - mod-rewrite

This question already exists:
Closed 11 years ago.
Possible Duplicate:
Css and javascript Not Loading in rewrite rule
After using only rewrite rule
RewriteEngine On
RewriteRule ^profile.php$ profile.php
and when i load profile.php the css and javascript are loading
but when make a change in rule and add condition
RewriteEngine On
RewriteCond %{REQUEST_URI} !/profile.php$
RewriteRule ^profile.php$ profile.php
and then the js and css are not loading
Coding of profile.php is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://localhost/css/profile.css" />
</head>
<body>
<table><tr><td><div class="image"><ul><li>My</li></ul></div>
</td></tr></table>
</body></html>

it's because the RewriteCond says : apply the followingRewriteRuleonly if the url doesn't only contain /profiles
you should write it like :
RewriteCond %{REQUEST_URI} /profile.php$
(without the exclamation mark)
in add:
If you don't want your mod_rewrite Rules to be apply on scripts and other specific files request, you should write a Rule for them.
E.g.
RewriteRule \.(css|jpe?g|gif|png)$ - [L]

Related

DocC index shows a blank page when using MAMP

I am trying to perform a POC for the company I work to see the potential value we can get by using DocC in our project.
Before my development, I saw the 4 videos related to DocC from WWDC 2021, visit Apple developer site and read some pages and blogs to gather some information and thoughts.
For my development, I started using MAMP on my dev machine before pushing the work to the server.
So far, I think I have done all the necessary steps to host the doccarchive on the website. However, I wonder if I have missed something as my index.html looks blank.
The code I used is:
index.html (main)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DocC POC</title>
</head>
<body>
<h2>Welcome</h2>
<button onclick="location.href = 'documentation/index.html';" id="myButton" class="float-left submit-button" >Read data framwework documentation</button>
</body>
</html>
.htaccess
# Enable custom routing.
RewriteEngine On
# Route documentation and tutorial pages.
RewriteRule ^(documentation|tutorials)\/.*$ Data.doccarchive/index.html [L]
# Route files and data for the documentation archive.
#
# If the file path doesn't exist in the website's root ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# ... route the request to that file path with the documentation archive.
RewriteRule .* Data.doccarchive/$0 [L]
File structure
Picture prooving that the doccarchive is not empty
Picture of blank page
Any ideas??
I was able to try it on github pages and was showing blank until I used the path {base path}/documentation/{project name}
so in your case try to replace index.html with your project name

Codeigniter deployment problem while hosting to domain server

The project locally works fine $config['base_url'] = "localhost/";
Codeigniter is getting the default controller welcome and login.php, but login.php is not getting the resources from assets folder
all the get requests for a resource are not found. When I inspect I get errors
xGET example.com/assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css
net::ERR_ABORTED 404
CodeIgniter folder structure in Cpanel public_html
+application
+assets
+system
index.php
.htaccess
I've configured the application/config/config.php
$config['base_url'] = 'www.mysite.com/';
$config['index_page'] = '';
I've configured the application/config/autoload.php
$autoload['packages'] = array('url');
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
the pages are loading resources:-
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css">
Rather than using href="<?php echo base_url();?>assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css"> just use href="/assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css">
Also, add http:// or https:// to your base URL depending on your SSL status.
Try using link_tag from html helper.
First load html helper in controller, or make it autoload in config/autoload.php
$autoload['helper'] = array('html');
Then try putting this in your header block of view file:
<?php echo link_tag('assets/TEMPLATE/LoginPage/vendor/bootstrap/css/bootstrap.min.css') ?>

W3C Error: X-UA-Compatible HTTP header must have the value IE=edge, was IE=Edge,chrome=1

I have this error from W3C Tool...
I changed my code from
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
to
<meta http-equiv="X-UA-Compatible" content="IE=edge">
but the tools still show me the same error message...
I found the solution...
I must change this in .htaccess file too...
Hum, I have changed it in the HTML files but doesn't work, When I fixed it in .htaccees file it works, very strange :)
Old code:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=Edge,chrome=1"
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
New code:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=Edge"
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
And everything is working perfect now :)

How to access public folder in laravel 4?

I was trying to add some styling in my localhost(wamp) lavarel project....
This is my style.css file located in public folder
p{font-weight:bold; size:20px; color:red;}
This is hello.blade.php file located in app/view folder
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="{{ URL::asset('style.css') }}">
</head>
<body>
<p>Test</p>
</body>
</html>
& My routes.php file is having following code:
Route::get('/',function(){
return View::make('hello');
});
.htaccess file located in root directory is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I am trying to access that hello page by localhost, Test content is visible without any styling. Can anyone tell me what is going wrong with me??
Your directory structure is different from the default one shown here
You have to put the packages folder and these files into the public directory:
.htaccess
favicon.ico
index.php
robots.txt
Then to make your site work again change the document root of your apache server to path/to/application/public
There's a reason for the public directory. When you put it on a server on the internet you gain additional security because the user can only access what is in the public directory. (because the domain is pointing to this folder) If you use your current setup everybody could see your whole application. For example one could enter example.com/app/config/database.php and would see your database password.
Put it like this:
<link rel="stylesheet" href="{{ asset('style.css') }}">
Without URL::

Where do javascript and css files go in a laravel project

Where should static javascript and css files in a Laravel 4 application. For the sake of my own understanding, I'm not interested in using any sort of assets or packages yet.
I tried putting them under public/js and public/packages to no avail, getting the following 404 errors in my page:
GET http://localhost/~myuser/mytest/packages/test2.js 404 (Not Found)
GET http://localhost/~myuser/mytest/js/mytest.js 404 (Not Found)
Here is what my .htaccess file looks like for reference:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~myuser/mytest/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
All assets should be placed in the public folder
public/js
public/css
public/fonts
public/images
You can access the assets using the asset() method or the Laravel HTML helper methods HTML::script and HTML::style.
i.e to include Javascript file:
- <script src="{{ asset('js/yourfile.js') }}"></script>
- {{ HTML::script('js/yourfile.js') }}
Hope this helps!
Inside the laravel folder you got public folder put css and js files here and access like this
<!doctype html>
<html lang="en">
<head>
<title>{{$title}}</title>
{{HTML::style('css/style.css')}}
</head>
<body>
#include('layouts.nav')
#yield('content')
</body>
</html>

Resources