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".
Related
It took me 2 hours but I can't figure it out and I don't know how to google a solution.
This is my Rewrite-Rule in the .htaccess-file:
RewriteCond %{REQUEST_URI} ^/blog/(.*)
RewriteRule ^blog/(.*) http://localhost:2368/$1 [P]
When I call example.com/blog, it redirects my to my ghost-blog running in nodejs (port 2368).
The problem: The blog itself loads css and js files with absolute paths:
<link rel="stylesheet" type="text/css" href="/assets/built/screen.css" />.
So it tries to load example.com/assets/built/screen.css.
But the file is reachable at example.com/blog/assets/built/screen.css
How can I solve this?
You have 3 alternatives:
Change the links/scripts source to /blog/assets/...
Change the file locations to /assets
Use a RewriteRule
.htaccess
RewriteCond %{REQUEST_URI} ^/assets(.*)\.(css|js)$
RewriteRule ^(.*) /blog/$1 [L]
RewriteCond %{REQUEST_URI} ^/blog/(.*)
RewriteRule ^blog/(.*) http://localhost:2368/$1 [P]
Here's the rule working: .htaccess tester
I assume that the files are being served by apache2 and not by the ghost-blog running in node.js. But if it's the latter,it will still work since after redirecting it will go the next rule. But you can also do the following:
RewriteCond %{REQUEST_URI} ^/assets(.*)\.(css|js)$
RewriteRule ^(.*) http://localhost:2368/$1 [L]
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!
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 have a htaccess with this content:
RewriteEngine on
RewriteBase /new/
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(.*)\.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^(.*)$ index.php?page=$1 [L]
The URL im working on is some like:
http://www.example.xy/new/
When I call a link like this:
test
URL should come up with
http://www.example.xy/new/aaa/bbb/ccc
Problem is, no matter what I do, all my css, js, and images are gone because I have them included like
<link href="style.css" ... />
this ends up in
<link href="aaa/bbb/ccc/style.css" ... />
how can I deny this or what am I doing wrong?
My .htaccess is based on several tutorials and some qoogle searched posts...
RewriteCond seams not to work well
works fine, It's the implementation
Add this to your html head section to fix your css, js problem.
<base href="http://www.yoursite.com" />
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]