i have problem in loading css file and image file while using url rewriting with this rules :
RewriteEngine on
RewriteRule ^showProject-([^/]+)-([0-9]+)\.html$ showProject.php?id=$2
i get this url :
localhost:8080/coders_ring/project/test/1.html
real url is :
localhost:8080/coders_ring/showProject.php?id=1
also i test in get url css file like this but not solution :
<link href="style/master_style.css" rel="stylesheet" type="text/css" />
<link href="/style/master_style.css" rel="stylesheet" type="text/css" />
any body have a solution to load css and image file with this url rewriting ?
Try to add a base href tag in your showproject.php file
Add this
<base href="http://localhost/coders_ring/" />
Related
I have a .htaccess file that redirects all the URL request to my index.php
AcceptPathInfo On
RewriteEngine on
RewriteBase /Projects/tester/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
Inside my index.php I have a code that include the URL file:
<?php
if(isset($_GET['request'])){
include('pages/'.$_GET['request'].'.php');
}else{
echo 'index';
}
?>
If my URL is localhost/Projects/tester/green my index will include a file called green.php that exists inside the folder pages.
inside pages/green.php I have this code:
<link rel="stylesheet" type="text/css" href="style.css">
<div id="greenBox">
This box is green!
</div>
When I run that URL I can see a large green div with an text inside.
Great, now lets create a folder called subs inside the folder pages and create a file called yellow.php
<link rel="stylesheet" type="text/css" href="style.css">
<div id="yellowBox">
This box is yellow!
</div>
When I run this URL localhost/Projects/tester/sub/yellow I can see the text but the style.css don't load (I can't see the yellow div).
If all the content is being included in the index.php and style.css file is in the same folder as the index.php, why green.php can load the style.css but the yellow.php not?
I can see the yellow div only if I add ../style.css inside the yellow.php, but if it is to work on this way, I believe we should use ../style.css on green.php while in yellow.php use ../../style.css, no?
Is there a way to solve this? is problem in .htaccess?
Of course the external browser doesn't understand where your files are located on the server, so if you are in the following situation (from the browser's perspective):
http://localhost/Projects/tester/green
-> hey browser, load "style.css"
-> browser loads http://localhost/Projects/tester/style.css
But if you change the "virtual" path:
http://localhost/Projects/tester/sub/yellow
-> hey browser, load "style.css"
-> browser loads http://localhost/Projects/tester/sub/style.css
So you have three solutions here, in order of my personal preference:
1) Use absolute URLs for loading css data, optionally using a PHP var:
<link rel="stylesheet" type="text/css" href="/Projects/tester/style.css">
<link rel="stylesheet" type="text/css" href="<?php echo $base_path; ?>/style.css">
2) Use the <base> html element in head: (warning: it applies to ALL relative urls in the page: links, images, etc.)
<head>
<base href="http://localhost/Projects/tester/" />
</head>
3) If using absolute URLs is not an option, you can calculate how many "virtual subdirectories" you are down and generate a prefix like this:
<?php
// first calculate $virtal_subdirs_number
$relative_urls = str_repeat("../", $virtual_subdirs_number);
?>
<link rel="stylesheet" type="text/css" href="<?php echo $relative_urls; ?>/style.css">
Its because the style.css is in parent directory of yellow.php, So for accessing a file in parent directory you must have to give path like ../style.css which mean look for it in one directory back and /style.css mean in the current directory which contain yellow.php
I am new on .htacees. I am trying to make user friendly URL for users using mode rewrite. My problem is that when i open "user.php" page using .htaccess re:write it can't load the CSS file or images file and show like this.
Sign up
My account
Hi
My Profile
My account
Logout
Help
© 2014 Company, Inc.
I have a link like:
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
New link is something like and its work 100% right for me.
http://localhost/www.zeeshan.com/user/zeeshan06
my .htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([^/]+)$ user.php?name=$1 [NC,L]
My CSS file path css/style.css , css/bootstrap.css, bootstrap.min.css in the www.zeeshan.com folder
<head>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
with out .htaccess page work well and show css of div,panel etc. But using .htaccess
re:write its cannot open css file and images file. please help me to solved my problem. Thanks..
Your paths for your CSS files are relative. So when you load up http://localhost/www.zeeshan.com/user/zeeshan06, your browser is looking for CSS files in a folder called http://localhost/www.zeeshan.com/user/. You need to change your paths to:
<head>
<link href="/www.zeeshan.com/style.css" rel="stylesheet" type="text/css"/>
<link href="/www.zeeshan.com/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/www.zeeshan.com/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
If you put a static link on each page inside the <base> tag you'll need to change it all over again after deploy.
use this:
<base href= "<?php echo "http://".$_SERVER['HTTP_HOST']."/your_folder/" . "/>" ; ?>"
so you'll can upload to production and will never need change it again.
I try to create Search Engine Friendly URLS like this;:
RewriteRule ^m/([0-9]+)$ my.php?id=$1
However, it gets the page without CSS.
If I write like this:
RewriteRule ^([0-9]+)$ my.php?id=$1
it gets the page with CSS without any problem.
How can I solve it?
When you write CSS references like this:
<link rel="stylesheet" type="text/css" href="style.css">
it's a relative URL. On http://example.com/, that points to http://example.com/style.css, but on http://example.com/my/1 it points to http://example.com/my/style.css, which doesn't exist.
Using an absolute URL fixes this:
<link rel="stylesheet" type="text/css" href="/style.css">
This can be fixed by adding a base attribute to the head tag of each page:
<base href="http://www.example.com/" />
or add / before the css.
<link rel="stylesheet" type="text/css" href="/stylesheet.css">
What was happening was that when you were redirecting the page, it was also looking for the css in my/css instead of css adding the above will fix that.
I have following code for my header.php file, in the includes folder.
<html>
<head>
<title>Health Mate</title>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link href="stylesheets/public.css" media="all" rel="stylesheet"/>
</head>
<!-- Some more code-->
</html>
I have pasted favicon.ico in the includes folder itself.Problem is the favicon is not setting up.Also If i redirect user to some site on submit button like yahoo.com . My site is taking favicon of yahoo. Please suggest some solution. Also tell me if favicon needs to be .ico file or it can be .png as well?
You should have necessary path needed to locate your favicon.ico image.
Eg: If your folder is structured this way:
/mysite
/includes
favicon.ico
index.php
If you're going to use it in index.php you should include the necessary path needed like this:
<link rel="icon" href="includes/favicon.ico" type="image/x-icon" />
Note: for checking if your like get the path towards your icon image..
you could check your web page source code using ctrl + u. Then click the href path linked if it displays the image it means your path is correct.
You have to put favicon.ico in to root directory of your website such that anyone can access it by yourdomain.com/favicon.ico. yourdomain.com/includes/favicon.ico will not work without a link tag.
If you can't put the favicon on the root folder for your domain then you have to use this code and change the href attribute to match the path to the favicon relative to the root of your site. i.e. /includes/favicon.ico
<link rel="Shortcut Icon" type="image/ico" href="/includes/favicon.ico">
I would recommend converting the file to an actual .ico using http://www.icoconverter.com/ or some equivalent tool.
The following rule works, but it changes the URL in the address bar, which is not intended.
RewriteRule ^network/(.*)$ http://www.example.com/network.php?networkUrl=$1 [L]
The following rule redirects, the URL stays the same, but all the images, includes in the network.php file become referenced incorrectly...
RewriteRule ^network/(.*)$ network.php?networkUrl=$1 [L]
Is there a way to make this work?
This is because your browser interprets paths as relative.
To solve this reference your images and CSS with absolute paths, i.e. <img href="image.jpg" /> becomes <img href="/image.jpg" />
Same applies for css so
<link href="stylesheets/foo.css" media="print" rel="stylesheet" type="text/css"/>
becomes
<link href="/stylesheets/foo.css" media="print" rel="stylesheet" type="text/css"/>
In this way all resources links works as expected when referenced from any depth as /foo/bar/baz/script.php and so on.
Setting a base href HTML tag in your page could help too:
<base href="http://www.domain.com/" />
then all your relative images, stylesheets or javascript files will be relative to this base href.
http://www.w3.org/wiki/HTML/Elements/base