mod_rewrite .htaccess - Stylesheets mess up - .htaccess

I'm trying to rewrite some URL's on my website, and it works fine, I just have some issues with the stylesheets. All stylesheets works at index.php but not when url's like: localhost:8888/folder/path/(1,2,3,4)
I have my stylesheets in a file where they're listed like this:
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="includes/css/site.css"/>
<link rel="stylesheet" href="includes/css/viewProfile.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="includes/css/viewProvider.css" type="text/css" media="screen" title="no title" charset="utf-8">
Is there a way to fix this with mod_rewrite or how would I fix this?

This is because you use a relative path to the style sheets. Note that the browser sends requests to
localhost:8888/folder/path/includes/css/...
in that case. If the styles always reside in that configuration at the server root, you could simply make the relative URI an absolute one. Or you remove the path portion for CSS files on the server side.

Related

Angular production build with index.jsp instead of index.html

I want want to create an index.jsp file instead of index.html while doing production build. This weird requirement is for capturing the header part which we will getting from other Oracle Authentication Manager so I want load my appliation from index.jsp. My index.jsp should look something like this
<%# page language="java" import="java.util.*" session="true" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CardEncryption</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.3ff695c00d717f2d2a11.css"></head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.06daa30a2963fa413676.js"></script><script type="text/javascript" src="polyfills.9a8743e2009b1e7b1fbd.js"></script><script type="text/javascript" src="main.dcf4ad6dff6130812df3.js"></script></body>
</html>
Any suggestion to do this.
I suppose you only want the index.jsp when doing the production build. The development process should still use index.html
In that case you should
Create a index.jsp file in the same directory as your index.html file (so you have both).
Update your angular.json file's production configuration by adding an index property to your production configuration like this:
That will make sure that it uses index.jsp when you build with --prod, but still uses index.html for development.

Ejs file not getting rendered when the URL of anchor tag, href is modified

<a class="active" href="/dashboard">
<i class="fa fa-dashboard">
</i><span>Dashboard</span>
</a>
router.get('/dashboard',function(req,res,next){
res.render('dashboard');
});
With this part above, the "dashboard.ejs" file gets rendered as expected but when I modify it as shown below, the "dashboard.ejs" file does not get rendered!
<a class="active" href="/dashboard/dashboardcontent">
<i class="fa fa-dashboard">
</i><span>Dashboard</span>
</a>
router.get('/dashboard/dashboardcontent',function(req,res,next){
res.render('dashboard');
});
and i'm wondering why it is failing to render the file when such small changes are made.
Any help ?
Before finding the solution:
app.use(express.static(path.join(__dirname, 'public')));
As we can see, I had no virtual path prefix created for files that are served by the express.static function !
The solution:
To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
app.use('/static', express.static(path.join(__dirname, 'public')));
I have also added this '/static' to all CSS, JS, Images links in "layout.ejs" file as shown below:
<!-- Bootstrap core CSS -->
<link href="/static/stylesheets/bootstrap.css" rel="stylesheet">
<!--external css-->
<link href="/static/font-awesome/css/font-awesome.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="/static/stylesheets/zabuto_calendar.css">
<link rel="stylesheet" type="text/css" href="/static/javascripts/gritter/css/jquery.gritter.css" />
<link rel="stylesheet" type="text/css" href="/static/lineicons/style.css">
<!-- Custom styles for this template -->
<link href="/static/stylesheets/style.css" rel="stylesheet">
<link href="/static/stylesheets/style-responsive.css" rel="stylesheet">
<script src="/static/lib/jquery.min.js" type="text/javascript"></script>
<script src="/static/dist/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/javascripts/chart-master/Chart.js"></script>
<script src="/static/select2Plugin/select2.min.js"></script>
<link rel="stylesheet" href="/static/select2Plugin/select2.min.css" />
Source: https://expressjs.com/en/starter/static-files.html
Hope this will be found helpful.

why slim requires full directory path for loading external assets(js/css) file

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="/slim/app/views/animations/jquery.min.js"></script>
<script type="text/javascript" src="/slim/app/views/animations/bootstrap.min.js"></script>
<link rel="stylesheet" href="/slim/app/views/animations/bootstrap.min.css">
</head>
<body>
<div class="container">
hello
</div>
</body>
</html>
I have to specify full directory path for loading the js and css files
(jquery.min.js and bootstrp.min.js and bootstrap.min.css).Here i have
(/slim/app/views/animations/) as the directory which contain all the
files. if currently i am in the views directory i should use the
(animations/whatever the file name) but it is not working in these
way. but if i use the full directory path it all works fine. why these
is happening can anyone explain.
(slim) is my root directory where i installed slim
Using Relative paths is not how you typically work with Slim. Your assets (JavaScript/CSS/images, etc) should be referenced absolute from your views:
src="/assets/js/myapp.js"
Routed URLs do not map directly to file system based resources because templates should not be accessed by URL publically - they are only served by the controllers.
A common slim file structure looks like this:
app/
public/index.php
templates/
view.html
assets/
images/
js/
css/
Some add the assets subfolders directly into the public folder.
Others have those folders on the root level.
However, in general, public assets (e.g. CSS, JS, images) should be beneath the public document root (accessible to the public).
One thing that could be helpful if you do not like this behavior is to use Slim's basePath variable.
You should be able to set the base URL as a View variable in a slim.before callback in your index.php so that it is available to all routes like this:
$app->hook('slim.before', function () use ($app) {
$app->view()->appendData(array('baseUrl' => '/base/url/here'));
});
or
$app->hook('slim.before', function () use ($app) {
$posIndex = strpos( $_SERVER['PHP_SELF'], '/index.php');
$baseUrl = substr( $_SERVER['PHP_SELF'], 0, $posIndex);
$app->view()->appendData(array('baseUrl' => $baseUrl ));
});
And then apply it to the references in your HTML tag of the base template file and that's it.
<link rel="stylesheet" type="text/css" href="{{ base_url() }}/css/style.css" />
Or use Uri::getBaseUrl(), e.g.
$basePath = $request->getUri()->getBasePath();

Magento prod site clone not working like prod

I'm seeing different output from my production clone site than on production. The most obvious difference I can see so far (and there is probably more) is that the js/css references in the main document look to have been min-ified on production:
<link rel="stylesheet" type="text/css" href="https://www.example.com/media/css_secure/eb0df35e22a81d2150af7faddb2a014c-v2.18.css" media="all" />
<script type="text/javascript" src="https://www.example.com/media/js/f081fea0e1f96e90201edfc964382601-v2.18.js"></script>
But in my production clone, they come back like this:
<link rel="stylesheet" type="text/css" href="/git/magento/skin/frontend/responsive/default/css/styles.css" media="all" />
<link rel="stylesheet" type="text/css" href="/git/magento/skin/frontend/base/default/css/widgets.css" media="all" />
<link rel="stylesheet" type="text/css" href="/git/magento/skin/frontend/base/default/css/amasty/amfpc/styles.css" media="all" />
<link rel="stylesheet" type="text/css" href="/git/magento/skin/frontend/responsive/default/css/AutoComplete.css" media="all" />
...
<script type="text/javascript" src="/git/magento/js/prototype/prototype.min.js"></script>
<script type="text/javascript" src="/git/magento/js/lib/ccard.min.js"></script>
<script type="text/javascript" src="/git/magento/js/prototype/validation.min.js"></script>
<script type="text/javascript" src="/git/magento/js/scriptaculous/builder.min.js"></script>
...
There are 2 problems I see:
I would like my clone to have the same min-ified CSS and JS as prod
The CSS and JS urls for the clone start with "/git/magento" which is actually the name of my Magento ROOT folder on disk, so that's not right and they all come back as 404s.
When I did the production clone, I didn't bring over any of the files in /media (that's the advice I got). Is there anything I should be doing differently? I also followed these steps: https://magento.stackexchange.com/questions/35087/how-can-we-stop-a-magento-site-clone-from-redirecting-back-to-live-site
Why is the same code returning different CSS and JS references?
Found the issue. I had to create the MAGENTO_ROOT/var and MAGENTO_ROOT/media folders and give them the correct permissions. This was very helpful: http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html#privs-after
I guess the problem was that the /media folder was not writable to the web server process, so it couldn't save the minified/cached version of the js/css.

CSS and Images on windows azure

The project is done on MVC5, and when i publish the project through visual studio on azure, the images and css effects cannot be done. I did try through the Bundling.config but still cannot get it done. i have an img folder inside Content (it has all the images).
I have the following in my bundle config file:
bundles.Add(new StyleBundle("~/Content/img").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/base.css",
"~/Content/parallaxstyle.css",
"~/Content/bootstrap.css",
"~/Content/pricing.css",
"~/Content/pricing2.css"));
and in view:
#Scripts.Render("~/Content/img")
But it doesn't even render the css files.
This is the root.
The layout view:
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title</title>
#Styles.Render("~/Content/css")
#Styles.Render("~/Content/img/demo/_small")
#Scripts.Render("~/bundles/modernizr")
#Styles.Render("~/Content/bootstrap.css")
#Styles.Render("~/Content/base.css")
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Josefin+Slab">
<link href='http://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
</head>
<body>
That's because you created a StyleBundle, and are trying to render a ScriptBundle.
Change this:
#Scripts.Render("~/Content/img")
To this:
#Styles.Render("~/Content/img")
Note that if you have an actual folder at ~/Content/img, consider changing the name of the bundle so that there is no name clash.

Resources