Where to place css file for perl cgi script? - css

I am currently using Apache Server to run my script with the URL:
http://MY_IP/cgi-bin/example.cgi/
which works fine.
However, I'm not sure where to put my .css file. I read that it doesn't belong in the cgi-bin directory.
This is what I have in my 000-default.conf file.
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
I have tried placing it in here and used:
<link rel="stylesheet" type="text/css" href="/var/www/html/login.css"/>
but to no avail.
Could someone please help me out with this?
Thank you.

Looks like you put it in the right place. It's just the href that you've got wrong.
Your Apache config contains this line
DocumentRoot /var/www/html
This means the the root of your web site is at /var/www/html. So a URL that looks at the root of your web site will translate to a file in that directory.
The href attribute is a URL, not a file path. Therefore, if you put your login.css in this directory, then the correct link would be:
<link rel="stylesheet" type="text/css" href="/login.css" />
But many people would put their CSS files in a subdirectory called /css/ (which maps to /var/www/html/css on your filesystem). If you do that, then the correct link becomes.
<link rel="stylesheet" type="text/css" href="/css/login.css" />

Although it is always a matter of personal preference, a lot of people create directories under their root directory for javascript, css, images, etc. -- so any static pages would be in /var/www/html, and assets are in subdirectories, such as /var/www/html/css, /var/www/html/javascript, /var/www/html/images, and so on.
In your static html pages (in /var/www/html), you can reference these using relative links, e.g. <link rel="stylesheet" href="css/style.css">, <script src="javascript/my-script.js"> or absolute links, e.g. <link rel="stylesheet" href="http://MY_IP/css/style.css">. For pages on your server but not in /var/www/html, using /css/style.css is the appropriate form of the relative link, as / is equivalent to the local directory /var/www/html (that is what setting DocumentRoot in Apache does), so /css accesses the local directory /var/www/html/css.
You can also use the <base> tag in the page head to set a base href for all your relative links:
<base href="http://MY_IP">
Then any relative links (e.g. href="css/style.css") will automatically be interpreted as (e.g.) http://MY_IP/css/style.css.

Related

how to fix css loading problem on production server

my website is now hosted on a server and the URL is like this
test1.test.com
but now I have to move it to another hosting which they don't have this ability and I had to change it to:
test.com/test1
until now everything is working except the CSS and JS files I get 404 not found error.
and in my case, I didn't change anything and this is how I am loading the CSS files
<link rel="stylesheet" href="{{ asset('css/main.css') }}">
does anyone have any idea how can I fix this?
of course, i tried to add the (test1) before the {{ asset('css/main.css') }} but it didn't change anything.
PS: the source code is not saved under sub directory the /test1 is just routing to a load balancer.
and here are the apache2 setting file for docker image:
<VirtualHost *:80>
DocumentRoot /var/www/html/web
<Directory /var/www/html/web>
AllowOverride None
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/app_error.log
CustomLog /var/log/apache2/app_access.log combined
</VirtualHost>
the deployment is on a cloud server using docker image and locally it's working in any way I am accessing the website.
any ideas or setting it might help?
thanks in advance
It uses a relative path, so if your "base"-path is /test1, a relative path would look in a folder called /test1/css/ for the css file.
Depending on your symfony version, the asset() function allows an absolute config parameter to make the path absolute, therefore: what happens if you include the static files like this:
<link rel="stylesheet" href="{{ asset('css/main.css', absolute=true) }}" />
if you're on a version later than 3.0, use:
<link rel="stylesheet" href="{{ absolute_url(asset('css/main.css')) }}" />
i just want to thanks every one tried to help me with my problem but now i found the problem and the solution:
the problem has nothing to do with symfony it self but it was related to the hosting service its seems to be that the service provider is using ingress and Kubernetes and ingress does not support static files (css, js) loading. there is work arounds if you have access to the server settings files but in my case there was not.
my solution was to serve the static files as a service. its somthing like private CDN for my assets and all the static files.
thanks again and if any one had the same case i will be more than happy to help.

htaccess require local breaks background images

I have my image folder protected from browsing using the following line in my .htaccess file:
require local
This provides the security I require, but prevents CSS background images from displaying.
style="background: url(../data/profile_img/profile_10.jpg?x=1444352490)"
Accessing the file using an img tag works, but css does not.
thanks in advance
I solved this myself.
Turns out my .htaccess was not being honoured at all.
The solution was to remove
+FollowSymLinks from the apache config file, in the directory area
<Directory "/var/www">
AllowOverride All
</Directory>

Domain Frame redirect not responsive

So I have two Domains where one is just a domain without Webspace.
The other Domain shows to a Wordpress Installation which works fine. (www.braintwist.org)
I tried to Frame redirect the external Domain to this directory and it also works out.
(www.thebraintank.de redirected to www.braintwist.org)
The Site gets loaded in a Frameset. Unfortunatly, when I open up the site on a mobile phone the scale stays at desktop size (so the font-size is to "small" etc.)
I think its because the Frameset.
Is there a way to redirect the Domain to an external Webspace without it being loaded in a Frameset?
best regards
You could write a small php script like this (this would need to be stored as index.php and would only redirect users accessing the index.php or the "plain" domain as URL):
<?php
header('Location: http://newlocation'):
?>
or use a .htaccess file:
RewriteEngine On
RewriteRule (.*) http://newlocation/$1
or
Redirect / http://newlocation/
In the first place mod_rewrite must be loaded and for the second .htaccess example you need mod_alias.
However, in both cases you will see the new URL in the address bar of the browser.
In order to keep the URL on the addressbar you could use
RewriteEngine On
RewriteRule (.*) http://newlocation/$1 [P]
to proxy requests. This, however, requires mod_rewrite and mod_proxy to be loaded (and might cause some slower performance as all requests are done "twice" in background).
See: http://httpd.apache.org/docs/current/rewrite/ for mod_rewrite documentation.
Create a .php document and upload it to your hosting. Don't create a frame forward in your domain setting, but point the domain to the created .php document. Then use the following code in your .php document to create the frame forward there.
<html>
<head>
<title>Your Title</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-
scale=1.0; user-scalable=0">
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
</head>
<frameset rows="100%" border="0" framespacing="0" frameborder="0">
<frame name="main" src="https://your-target-domain.com/" marginwidth="0"
marginheight="0" scrolling="auto"
noresize="noresize">
</frameset>
<noframes>
</noframes>
</html>
I created a link to a favicon as well. You can take this line out if you dont need it. If you need it, simply upload your favicon as "favicon.ico" into the same directory as the .php file.
Now you have a mobile responsive frame forwarding :)

Redirecting primary domain

This is a generic webhosting question,
I am trying to redirect, my primary domain to a subfolder in the 'www' folder, which consists of 3 folders
here is a better view
www ->
Folder1
Folder2
Folder3
Folder2 is where my drupal installation is , and this is where I want my domain to go directly
Right now what is happening is I type my domain name in the browser, abc.com, then I am presented with the above mentioned 3 folders and when I click the subfolder2, I can use drupal as per normal.
I am not sure what is needed to be changed, I am sure this can be done.
What sort of web server have you got? Is it one you are self hosting?
If it's apache you can change the home page to point to the new folder. HOWEVER if you are remotely hosting it this may be more difficult and you may have to physically move the whole installation to the root.
Another solution (not a nice one) is to do an HTTP redirect by creating an index.html in the home folder with
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;Folder2"></HEAD>
<BODY>
</BODY>
</HTML>
You can use .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?Primarydomain.com$
RewriteRule ^(/)?$ Folder2 [L]

Nginx static media, and problems with trailing slashes

Sigh... just when I thought I had figured out all the issues with trailing slashes in URLs for Django - and I start working with nginx...
So I'm configuring nginx to serve static media, and failing repeatedly - despite my config looking exactly like all the other static-media questions on SO. Eventually I realize that it's not the nginx config, but my HTML file, which includes a trailing slash on the .css file:
# hello.html (invalid)
<link rel="stylesheet" href="/media/css/hello.css/" type="text/css" />
# resulting log error
[error] 27705#0: "/home/www/static/css/hello.css/index.html" is not found
request: "GET /media/css/hello.css/ HTTP/1.1"
# hello.html (valid)
<link rel="stylesheet" href="/media/css/hello.css" type="text/css" />
By removing the trailing slash on the filename, it worked fine. But why? Shouldn't URLs end in trailing slashes?
I recently went through all my Django templates, adding slashes to every media file. Do I have to remove them all, or is there some configuration option in nginx that I'm missing?
Having the slash in the request will make most servers assume that you want the hello.css folder in the css folder. Obviously, that's going to confuse it.
Shouldn't URLs end in trailing
slashes?
Nope. Do a view-source for this page, or almost any other.
<link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">
See? No trailing slash.

Resources