I am trying to learn VueJS and Twig. I made my own (just for fun) MVC and that is working fine, the problem lies in not being able to include JS or CSS files.
When I press CTRL+U and view my source, I click on my javascript file and then the page reloads with the correct URL but I will still see my index pagina...
I have no clue what is causing this and -or how to fix this. Does anyone have any ideas on how to fix this?
root
htaccess
public
htaccess
My root htaccess file is:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
and the htaccess file in my public folder is
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
My layout (index) page is this:
<!DOCTYPE html>
<html>
<head>
<title>Beta</title>
<link rel="stylesheet" href="../../public/css/style.css" />
<script src="../../node_modules/vue/dist/vue.min.js"></script>
<script src="../../public/js/scripts.js"></script>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
As said, when I click on my CSS or JS file I see this in the source:
<!DOCTYPE html>
<html>
<head>
<title>Beta</title>
<link rel="stylesheet" href="../../public/css/style.css" />
<script src="../../node_modules/vue/dist/vue.min.js"></script>
<script src="../../public/js/scripts.js"></script>
</head>
<body>
Hello there!
</body>
</html>
Hope someone can help me out!
UPDATE:
I changed my htaccess to this:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L,NC]
</IfModule>
And now my CSS and JS are visible, but the node_modules (Vue) still shows this weird behavior of just showing the index page's source code.
Obvious rookie mistake!
You cannot include something from the "node_modules" folder. I used GULP to include and compile everything to one of my publically accessible folders and now I can include them perfectly fine!
Related
I try to rewrite rule url in .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^myfolder/([^/]*)$ /myfolder/index.php?link=$1 [L]
RewriteRule ^myfolder/([^/]*)/([^/]*)/([^/]*)$ /myfolder/functions.php?model=$1&id=$2&method=$3 [L]
So, it works. But, my css is not loading. I tried to find some solution and when i change:
<link href="css/colors/blue.css" rel="stylesheet">
to
<link href="css/blue.css" rel="stylesheet">
and remove blue.css from "css/colors" folder and add it to "css" folder. My css is loaded.
My question is How to load css in "css/colors/blue.css".
My laravel 5.2 app unable to fetch the stylesheet from the public/css directory on the production server but can fetch stylesheets on the local machine!
here is how I am linking my files:
<link href="{{asset('css/clock.css')}}" rel="stylesheet" media="all" />
I also tried bunch of different ways:
<link href="{{URL::asset('css/clock.css')}}" rel="stylesheet" media="all" />
OR:
{{HTML::style('css/clock.css')}}
but nothing worked on server!
but it is not able to fetch the css! when I check the page source, it shows me some other css file linked.. is it because of '.htaccess' file that I used to redirect to the public folder of my site?
you can have a look at enter link description here..
please help!
Why are u not trying url helper like this
<link href="{{ url('css/clock.css')}}" rel="stylesheet" media="all" />
Note:- css/clock.css is in public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
The asset() helper prepends the base URL to the path you supply.
But laravel keep js, css, and image files into public folder so you need to add public path like this:
href="public/{{ asset('css/style.css') }}.
Instead of doing this edit into this file:- vendor\laravel\framework\src\Illuminate\Foundation\helpers.php
function asset($path, $secure = null)
{
if($_SERVER['HTTP_HOST']=='127.0.0.1:8000')
return app('url')->asset($path, $secure);
else
return app('url')->asset('public/'.$path, $secure);
}
I want to hide a folder name from Address bar by .htaccess, that means hide myfolder name from: http://www.myweb.com/myfolder/mypage but only 1 internal css page link not work.
I used the below code collected from stockoverflow, Its hide folder name well but a internal page links not work.
Here others css and js link work well also.
Information: I have 2 css folder. One is root directory and others one
is myfolder directory.
Internal page link:
All css and js page link like as
<link href="css/style.css" rel="stylesheet" type="text/css" />
Try 1:
<link href="../myfolder/css/style.css" rel="stylesheet" type="text/css" />
Also try 2:
<link href="http://www.myweb.com/myfolder/css/style.css" rel="stylesheet" type="text/css" />
my htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+myfolder/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^myfolder/)^(.*)$ /myfolder/$1 [L,NC]
The problem is that the following rule only passes the request to files inside /myfolder if the request path does not already exist. But, since a /css/style.css also exists at the root, the test fails and preempts the rule.
RewriteCond %{REQUEST_FILENAME} !-f # if not a file
RewriteRule (?!^myfolder/)^(.*)$ /myfolder/$1 [L,NC]
The easiest way to resolve this would be to either rename the folder or css file inside the myfolder directory. The other way would be to append a query string tag like
<link href="css/style.css?myfolder" rel="stylesheet" type="text/css" />
and check for it within the .htaccess like
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{QUERY_STRING} ^myfolder$ [NC]
RewriteRule (?!^myfolder/)^(.*)$ /myfolder/$1 [L,NC]
I am using a small redirect to let my index.php resolve all parameters, but in some cases it can't find my javascript files anymore.
This small .htaccess rewrites all requests that don't exist to index.php.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1
RewriteRule ^(.*)/$ index.php/$1
A piece of my index.php where the javascript url returns index.php instead:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
www.mysite.com/foo is working fine
www.mysite.com is working as well
www.mysite.com/foo/foo isn't working. It returns index.php as a
javascript file when I inspect it with firebug.
Why is the relative path changed? I am redirecting to index.php so I'm expecting to be in that folder.
As an alternative: How can I get the full path of the javascript that is being requested for debugging purposes? Is there a way to find the .js requests that are being made by index.php?
Because of the extra slash, the browser thinks that your relative links (e.g. "scripts/jquery-1.10.2.min.js") have a URI base in a subdirectory. So you either need to make your links absolute instead of relative:
<script type="text/javascript" src="/scripts/jquery-1.10.2.min.js"></script>
Or add a relative URI base in your header:
<base href="/" />
The other thing here is that your second rewrite rule doesn't have any conditions. RewriteConds only get applied to the immediately following RewriteRule. The other thing is that the first rule will always get applied because (.*) matches everything, including URI's with a trailing slash. Thus the second rule never gets applied. You should always make the slash optional:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ index.php/$1
I have my website (a.com). Another person is pointing your domain (b.com) to my server. That is wrong.
Is it possible to redirect all traffic that comes from b.com for a generic 404 page? think this is possible with a file htaccess
Thanks you!
Edit
i can do this?
RewriteEngine On
RewriteRule ^(.*)$ http://www.b.com/$1 [R=404,L]
or
RewriteCond %{HTTP_HOST} ^www.b.com [nocase]
RedirectMatch 404 ^(.*)
You could do something like this:
UPDATE
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^domainb\.com$ [NC]
RewriteRule .* - [R=404]
You could also try a general forbidden error, like this:
order allow,deny
deny from b.com
allow from all
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} b\.com [NC]
RewriteRule ^ /404.html [R=404,L]
This will check if traffic is coming from b.com and if yes then it will redirect all the requests to a generic 404.html page.
How I did it was to put this code in the htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
</IfModule>
Which send the request to the index.html file. Then use the refresh function in html to redirect the file to the desired domain:
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<META http-equiv="refresh" content="0;URL=https://www.mydomain.co.uk/">
</head>
<body>
</body>
</html>