I have rewritten my url using htaccess .After navigating to the page, the layout distorts and no value fetched from the database is printed out.This is the main URL
http://www.deffsale.com/personalBusiness/PersonalBusiness.php?item=ladys%20Fashion&page=1
and I'm navigating to this page using this one
http://www.deffsale.com/personalBusiness/all/ladys-Fashion/1
This is my ht-access
RewriteEngine On
RewriteRule ^About-us AboutUs.php [NC,L]
RewriteRule ^personal-business personalBusiness [NC,L]
RewriteRule ^personalBusiness/all/([0-9a-zA-Z_-]+)/([0-9]+) personalBusiness/PersonalBusiness.php?item=$1&page=$2 [NC,L]
please help me solve this because it has been a disturbance past three months
You need to include this line just below <head> section of your HTML:
<base href="/personalBusiness/" />
so that every relative URL is resolved from that base URL /personalBusiness/ and not from the current page's URL.
It is a path issue with your CSS and images related to the rewrite rules. Add a rule like this before the other rules:
RewriteRule \.(js|css|jpe?g|png|gif)$ - [L]
which will allow those requests to be passed unmodified.
In addition, make sure the URLs for JavaScript, CSS and image files are coded relative to DocumentRoot. For example if your files are organized like this:
/ - index.php
+ css
+ base.css
+ color.css
+ images
+ logo.png
The style tags would be:
<link rel="stylesheet" type="text/css" href="/css/base.css">
<link rel="stylesheet" type="text/css" href="/css/color.css">
And images would be:
<img src="/images/logo.png" alt="logo">
As the other respondent suggested, you may use a base tag with relative URLs instead. In that case, you would code the tags like:
<base href="/">
<link rel="stylesheet" type="text/css" href="css/base.css">
<link rel="stylesheet" type="text/css" href="css/color.css">
And images would be:
<img src="images/logo.png" alt="logo">
The difference is that the base tag can be used to set the reference point for the relative URLs. Bear in mind the base tag will affect all relative URLs on your page.
Related
I have html in /html/test-html/index.html here. There are also css and images like this one: /html/test-html/css/style.css
When I open index.html in browser styles and images are loaded correctly.
When I'm trying to render it's contents by php echo function I get problems with 404 error, because paths in index.html and style.css are relative, like this one:
<link src="css/style.css" rel="stylesheet" type="text/css" />
So when I echo index.html contents in my script (i.e. by url like http://localhost/product1) browser tries to find style.css by this url:
http://localhost/css/style.css
But actually file is located in
/html/test-html/css/style.css
I think that good idea is to simulate URL like browser in http://localhost/html/test-html/, but actually we are in http://localhost/product1 (with RewriteRule), but without a redirect.
In other words, I want browser to think that http://localhost/product1 is http://localhost/test-html and server to think that http://localhost/product1 is http://localhost/index.php?r=product/view&id=1
Is it possible?
I have my website at root website .com/ I want to setup a folder like this website .com/us/
The folder /us/ is empty and when someone goes to it the folder shows the same content as what's in website .com but still staying on website .com/us/.
Here's the twist, if i wanted to show a different header.php or js or css file and this is loaded in to the domain website .com/us/, i need htaccess to use that instead of what's on website .com/. I will use the same directory structure.
Here's one of many ways you can go about it. It's a crude example using mod_rewrite and php5 that hopefully gets you in the direction you want to go.
Using the example below navigating to should behave like the following
http://example.com/ should show 'Content' with the header-default.php header
http://example.com/us/ should show 'Content' with the header-us.php header
http://example.com/some-other-directory/file.php should show 'Different Content in some other directory' with the header-default.php header
http://example.com/us/some-other-directory/file.php should show 'Different Content in some other directory' with the header-us.php header
.htaccess
<IfModule php5_module>
php_value auto_prepend_file /var/www/vhosts/example.com/httpdocs/header.php
php_value auto_append_file /var/www/vhosts/example.com/httpdocs/footer.php
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^us/?$ /index\.php?tpl=us [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteRule ^us/(.*)$ /$1?tpl=us [QSA,L]
</IfModule>
/header.php
<?php
$tpl = $_GET['tpl'];
if ($tpl === 'us') {
require_once $_SERVER['DOCUMENT_ROOT'].'/header-us.php';
}
else {
require_once $_SERVER['DOCUMENT_ROOT'].'/header-default.php';
}
?>
/header-us.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>USA</title>
<meta name="description" content="Welcome to the US section">
<link rel="stylesheet" href="/css/us/style.css">
<script src="/js/us/scripts.js"></script>
</head>
<body>
/header-default.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to index</title>
<meta name="description" content="Welcome to the DEFAULT section">
<link rel="stylesheet" href="/css/style.css">
<script src="/js/scripts.js"></script>
</head>
<body>
/footer.php
<p>user contributions licensed under cc-wiki with attribution required</p>
</body>
</html>
/index.php
Content
/some-other-directory/file.php
Different Content in some other directory
Like title, that rule:
RewriteRule pagtwo/pic/(.*) index.php?pic=$1 [PT,QSA]
Rule working, but not the file included by subdirectory for example
<link type="text/css" rel="stylesheet" href="css/base.css" media="all">
<img src="imgs/image.jpg">
and goes on
Directories are css, imgs and js, why they do not included correctly? Must I insert the absolute path for that directory?
Try adding this to you page header:
<base href="/">
Because you're using relative paths, what would normally resolve relatively from / won't woek when resolving relative from /pagtwo/pic/.
I want to make Friendly URLs, but when I try my PHP code works correctly but my CSS and JS files are not loaded correctly. It tries to get these files from different path.
I'm using WAMP, and I've created bsp directory for my project.
There are two folders for js and css files and I've used the css and js files in my php pages like
< script type="text/javascript" src="js/menu_config.js">< / script >
< link rel="stylesheet" type="text/css" href="css/menu.css" / >
and the .htaccess file code is here:
RewriteEngine On
RewriteRule ^products/([0-9]+)_([0-9]+).html$ products.php?maid=$1-$2 [L]
But when I browse through url http://localhost/bsp/products/2_7.html,
It does not load the js and css files.. at that time the path of js and css files becomes
http://localhost/bsp/products/css/menu.css etc
the css and js path should be http://localhost/bsp/css/menu.css.
I hope anybody will understand this problem as soon as possible.
This is just to do with your paths when including the files. You're currently using relative links, which means that "js/menu_config.js" will be appended onto the current URL.
Instead, you need an absolute path. By prepending your URLs with a /, you denote that you want to specify the path relative to the document root (rather than the current subdirectory). I'll leave out what the paths should be for now, filling them in is an exercise for you.
This should work
< script type="text/javascript" src="/js/menu_config.js">< / script >
< link rel="stylesheet" type="text/css" href="/css/menu.css" / >
I'm trying to rewrite some URL's on my website, and it works fine, I just have some issues with the stylesheets. All stylesheets works at index.php but not when url's like: localhost:8888/folder/path/(1,2,3,4)
I have my stylesheets in a file where they're listed like this:
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="includes/css/site.css"/>
<link rel="stylesheet" href="includes/css/viewProfile.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="includes/css/viewProvider.css" type="text/css" media="screen" title="no title" charset="utf-8">
Is there a way to fix this with mod_rewrite or how would I fix this?
This is because you use a relative path to the style sheets. Note that the browser sends requests to
localhost:8888/folder/path/includes/css/...
in that case. If the styles always reside in that configuration at the server root, you could simply make the relative URI an absolute one. Or you remove the path portion for CSS files on the server side.