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.
Related
I bought an SSL from comodo, and i used HTTP file auth for the validation process.
placed the .txt file in .well-known/pki-validation/ folder, but the validation is failing as the url leads to www.example.com.well-known/pki-validation/file.txt with the trailing slash missing.
attempted many htaccess codes but its not working. also tried to change the url by adding a trailing slash at the end of the url in wordpress settings but no luck.
any fixes is highly appreciated.
Slash missing before WP-content & Some uploaded images are not showing?
For Example:
URL:
www.example.comwp-content/uopload/2017
In this website some images not working
Maybe it's a bit late for you OP, but anyone facing a similar issue and comes across this post, this may be because of a redirection rule in your web server.
I had http redirecting to https and my rule was missing the trailing slash in my new URL, e.g. for Apache:
<VirtualHost *:80>
Redirect permanent / https://www.example.com
...
Fix this by adding the trailing slash:
<VirtualHost *:80>
Redirect permanent / https://www.example.com/
...
if your url completely looking like that : http:="" localhost="" mywebsite="" wp-content="" uploads="" 2020="" 08="" finance.jpg"
you should fix quotes from href.
wrong = style="background-image:url("<?php echo $imageuri['url'] ?>")"
correct = style="background-image:url('<?php echo $imageuri['url'] ?>')"
with " you finishing style quotes
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.
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 :)
I am using Apache2 to redirect from port 80 to port 8080 of tomcat. My url is like
<IP address of server:8080>/mymodule/
after redirecting my url looks like,
<IP address of server>/mymodule/
Now I want to remove "/mymodule", so what I have done is used
RewriteEngine on
RewriteRule ^/(.*)$ /mymodule/$1 [L,PT]
JkMount /* worker1
My problem is after doing this, my css,js, img files are not loading... Only my page is loaded, nothing else... How to rewrite expression to resolve this
If I am not using RewriteRule, my view page source look like this
<link rel="stylesheet" href="/mymodule/css/jquery.rating.css" />
<link rel="stylesheet" href="/mymodule/css/style.css" />
<script src="/mymodule/js/jquery-1.6.1.min.js"></script>
If I am using RewriteRule, my view page source looks like this,
<link rel="stylesheet" href="/mymodule/css/jquery.rating.css;jsessionid=684675C2B02778B6B8D8CDC0918F7320" />
<link rel="stylesheet" href="/mymodule/css/style.css;jsessionid=684675C2B02778B6B8D8CDC0918F7320" />
<script src="/mymodule/js/jquery-1.6.1.min.js;jsessionid=684675C2B02778B6B8D8CDC0918F7320"></script>
Help me to resolve this...
Change your RewriteRule like this:
RewriteRule !^/?mymodule/ /mymodule%{REQUEST_URI} [L,NC,PT]