htaccess redirect localhost - macos

I have
<link href="/smarter-computing/us/en/sc-mobile.css" type="text/css"/>
<script src="/smarter-computing/js/sc-common.js?fileversion-r21" type="text/javascript">//</script>
When I am working on these files locally I have to keep append //localhost/~vc/ before the path for JS and CSS files. I don't want to keep copy/pasting this path for the following and every <img> links in my code.
How can I use htaccess to redirect all url's pointing to //localhost/smarter-computing/ or /smarter-computing/ to append this path //localhost/~vc/ before my /smarter-computing path.
Thank you,
Vishwas

You can either make the document root your home directory in your apache config in localhost, or add this to the header of your pages:
<base href="/~vc/">

Related

view included in all files having bootstrap files path not working in diffrent route

Route::get('fullDetail/{productId}','productController#showSingleProduct');
http://localhost/laravel-ecommerce1/fullDetail/233
file containing bootstrap files path change from
http://localhost/laravel-ecommerce1/bootstrap.min.css
to
http://localhost/laravel-ecommerce1/fullDetail/bootstrap.min.css
Add this in your blade template
<base href="/laravel-ecommerce1">
<link rel="stylesheet" href="/bootstrap.min.css">
the assets are linked relatively and the / means link from the root

Spring Boot Context Path Static Files Not Found

I have a problem with my application not finding my static files. This however only happens on a certain level. As you can see from the code fragments below, the css, images, js, etc works on certain files and not on others. Not sure what I am missing here.
My Stack: Spring Boot, Thymeleaf
Part of my application.yml file:
server:
port: 8090
servlet:
context-path: /myapp
My application public resources directory structure:
/resources
/public
/css
/images
/js
My application template structure and where the styles and images work:
/resources
/templates/index.html (works)
/templates/admin/index.html (works)
/templates/admin/user/admin/showuser.html (does not work)
Code from /resources/admin/fragments/header.html (Used as a header file for other files)
<!DOCTYPE html>
<html>
<head>
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/index.html (works) (Does not include the header.html fragment)
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/admin/index.html (works) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Code from /resources/templates/admin/user/admin/showuser.html (does not work) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Not sure how to fix this.
Thank you!
When your urls don't begin with a slash /, they attempt to resolve the current directory. For example:
Page: /templates/index.html
Css: css/mycss.css
The browser tries to locate /templates/css/mycss.css
If the cases that don't work:
Page: /templates/admin/user/admin/showuser.html
Css: css/mycss.css
The browser tries to locate /templates/admin/user/admin/css/mycss.css
If you want to make sure your css works everywhere, you need to make sure the link points consistently to the correct location. I'm guessing something like this would work:
<link th:href="#{/css/mycss.css}" rel="stylesheet">
(Using Thymeleaf to add the context, and to make the path absolute.)

How I can call a file in CodeIgniter, that has existed in core folder

I am a absolute beginner of CodeIgniter, Now I was creating a simple project with CI. But I don't know how I can call a file that has existed in core folder.
Core folder is like the following
/core/bootstrap/bootstrap.css
I want to call bootstap.css from my view/admin/index.php
How I can call it?
I already try it like the following
<link href="/application/core/bootstrap/bootstrap.css" rel="stylesheet" media="screen">
but it still doesn't work.
You should not put your CSS files in the core folder. Best practice with CI is the following:
- application
- assets
-- css
-- js
-- images
- system
-- <all CI folders here>
Use a URL helper to point to the assets folder like:
function asset_url(){
return base_url().'public/';
}
more info on url_helpers
Then you can point to your assets in your view like this:
<link rel="stylesheet" href='<?php echo asset_url()."css/YOUR_FILE.css" ?>'/>
Look at documentation and read about url_helper.
Use internal links with function site_url() or base_url()
First of all I will not put my css files in the core folder.
I will create folder which is in the same level as in the "application" and "system" folder.
Secondly, you need to configure the base url at application/confi/config.php like
$config['base_url'] = 'http://localhost/NV/';
With in the folder "NV", I have my CI files such as "application" and "system".
Then in the view I will just use
<link rel="stylesheet" href="<?php echo base_url();?>css/ace.min.css"/>
In this case, the "CSS" folder resides as in the same level as "application" and "system" folders.

Access to root folder from subdomains (Codeigniter)

I have some trouble to access root dir files when using subdomains:
My css files located in css dir in the root.
If i use url "my-site.com/css/file.css" - everything okay
If i use url "en.my-site.com/css/file.css" - 404 error
How can i fix it? I don't want to hardcode path to all my css and js files.
Thanks
try this for for loading all images, styles, js
<link rel="stylesheet" href="<?php echo site_url('css/file.css'); ?>">
don't forgot to create directory in your main CI folder.
if you not able to get that like this:
<link rel="stylesheet" href="<?php echo base_url(); ?>css/file.css">
you have a server problems and it is not Codeigniter related ;)

.htaccess redirect for subfolder images and stylesheets

Is it possible with a .htaccess redirect to have all style sheets and image paths, that are located in a subfolder, point to the appropriate folder(images/styles) in the the root folder? With out having to change the path in each file.
Let me try to explain my situation a little better.
Im using an include (header.inc.php) that contains my doctype, stylesheet links
<link href="styles/layout.css" rel="stylesheet" type="text/css">
and a couple other html element/images.
That becomes an issue when header.inc.php in pulled into my subfolder files, because style/layout.css does not exist in that folder. Additionally there are
a couple images that break because of the same reason,
<img src="images/image.jpg">
the images folder does not exist…
In my current .htaccess file, I have the below script with my include path (for local testing). Is there something similar to the include_path script that can help with the issues listed above?
php_value include_path ".:/Applications/MAMP/bin/php/php5.4.4/lib/php:/Applications/MAMP/htdocs/site/inc"
Here is an example of the file structure/hierarchy.
[ROOT FOLDER]
index.php
/subfolder
subpage1.php
subpage2.php
subpage3.php
/subfolder2
subpage1.php
subpage2.php
subpage3.php
contact.php
/images
/styles
/scripts
/inc
You don't need to use rewrites to solve this you just need to now how to define the source properly in your HTML elements.
Don't do this
<link href="styles/layout.css" rel="stylesheet" type="text/css">
Do this
<link href="/styles/layout.css" rel="stylesheet" type="text/css">
What this has changed is that your path is no longer relative to the file being browsed to but is now relative to the root of your web site.
Hope that helps.

Resources