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]
Related
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.
I set up a maintenance page for my site so when users visit, they are returned with the 503 status and redirected to a custom maintenance.php page. So it works fine and I can clearly see in my browsers that it is properly returning 503 as long as I manually enter URL's in my search address bar.
The issue is if someone clicks a link to certain pages from a Referrer, let's say from Facebook, it will redirect them to the maintenance.php page but for some reason it fails to load the CSS files and images associated with it. The CSS files and images suddenly return a 503 status as well.
My site by default will also redirect "http" pages to use "https" and "www". If I run the same page in just "http", the CSS files and images will load.
Then, if I run the page in "https" with no "www" in the URL, the page will load the CSS files and images.
So it seems as long as "https" and "www" are both in the URL, the page, its' CSS files, and its' images will all return 503.
My 503 status is configured in my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.89$
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.php
RewriteRule ^.*$ /maintenance.php [R=503,L]
ErrorDocument 503 /maintenance.php
Header Set Cache-Control "max-age=0, no-store"
The server is running Apache. Is there a configuration I can use that will make sure the CSS files and images load when someone clicks a link that includes "https" and "www" in the URL?
Edit: It also seems the pages with this issue do not have their URL's redirect to maintenance.php either. Although they still display the maintenance.php content despite this.
It turns out the solution was simple. In my maintenance.php I just needed to change the relative paths to absolute paths instead for the CSS files and images by adding a "/" in front.
i.e.
Originally was:
<link href="css/maintenance.css" rel="stylesheet" type="text/css">
Changed to:
<link href="/css/maintenance.css" rel="stylesheet" type="text/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.
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 :)
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.