URL beautification - php

I can't seem to figure out how to add an extra "/" to the end of my website's URL without affecting the URLs that are referenced in the file.
So, I want to change the URL from
http://url.com/home
to
http://url.com/home/
without affecting the URLs that are embedded in the files.
Do you have any idea on how to do this?
Thanks,
Rob

You can use <base> tag in <head> section
<head>
<base href="http://mydomain.com/" />
</head>
With this all relative links will be prefixed with given base.

Related

Including external stylesheets in a PHP file

<link href="/app/app.css" rel="stylesheet" type="text/css">
The above is the code I'm using to access a stylesheet, but it's not working at the .
Some extra details:
This is in a .php file, but it's located within the head of an html section
I'm working on a temporary url (i.e. 'my.ipa.dd.res/mydomain.com/dir/'). This might be the reason it's not working.
Edit:
It's a stylesheet I'd like to use on several pages, which is why I'm trying to point to a root directory (so that I don't need the file in every single folder I create).
Well I think you need to store your root directory path as a string to include your css file with an absolute URL.
Something like :
<link href="{$absoluteRootPath}/css/styles.css" rel="stylesheet" type="text/css">
If you remove the leading slash it will look for the css file in the folder relative to the current.
<link href="app/app.css" rel="stylesheet" type="text/css">
Edit: to reuse in multiple scripts in different dirs you would need to specify an absolute path, so to avoid having to change it in multiple places when you go live (ie stop using the temporary url) you should define a variable.
<?php
// set absolute path to the stylesheet
$cssPath = 'http://my.ipa.dd.res/mydomain.com/dir/';
?>
And
<link href="<?php echo $cssPath; ?>app/app.css" rel="stylesheet" type="text/css">
Depending on your php architecture you may need to define $cssPath as a global or you may be able to add it to an existing config variable. This is completely dependent on your framework.
I've been having this same problem recently. Here's what worked for me
Now on the index page, replace link rel="/app/app.css" href="stylesheet" type="text/css"
with
?php include 'style.php' ?
And on the style.php page insert the following tags:
style and /style
You can put the regular CSS between those two tags. See if that works. BTW for some reason I can't insert the greater or less than symbols without making the code disappear... Forgive me, I'm new here..

CSS file being ignored?

I have a contact page on my site set up like this;
contact.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="webpage.css">
<?php include 'header.php'; ?>
</head>
...rest of content
I recently set up an htaccess page with some mod_rewrite changes.
So now, I have urls like
www.example.com/user
and
www.example.com/user/contact
When I look at www.example.com/user/contact the CSS is not recognized and the page does not print any of my divs but just some worded content.
So if I have
<div id="userinfo">
User info
</div>
It just displays "User info" on the left of the page without the div being recognized.
How can I fix this problem?
The href in your CSS is a relative link. So for www.example.com/user the browser will request the css file at www.example.com/webpage.css, but for www.example.com/user/contact it will request www.example.com/user/webpage.css
That may cause part of your problem and can be fixed by preceding your hrefs with a /, so href="/webpage.css". The / will cause the browser to always request from the root of your domain so it will always request www.example.com/webpage.css regardless of the page you're on. If your css is inside some folder within your DocumentRoot (I assume you're using Apache here), you should be providing the full path to the file from the start of the doc root so possibly something like href="/css/webpage.css"
In the comments, Michael is also correct that you may have a rewrite rule error so please add that information to your question.
Use absolute URL beginning from /:
<link rel="stylesheet" href="/webpage.css" />

CSS <link> href loses leading slash, utilizing SilverStripe

I am using SilverStripe as a CMS (http://www.silverstripe.com/services/why-choose-us/open-source-cms/) instead of Joomla or Drupal, and it has been a great experience for the most part so far. This problem however, is so strange that I am not even sure that SilverStripe has anything to do with it. Basically, links to CSS files that are set in a template are losing their leading slash when the markup is output to the browser. Obviously this can be very problematic.
This is the head section in the relevant template:
<!DOCTYPE html>
<html>
<head>
<% base_tag %>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=720, maximum-scale=1.0" />
<title>$Title</title>
<link rel="stylesheet" type="text/css"
href="/framework/admin/thirdparty/jquery-notice/jquery.notice.css?m=1342411326" />
</head>
The links are actually generated into the template dynamically, but I put this one link in myself to isolate the issue. Even manually added into the template, the link markup will end up with href="framework/admin/thirdparty/jquery-notice/jquery.notice.css?m=1342411326", the original link minus the leading forward-slash,/. Does anyone have an idea how this might happen? Doesn't matter if I'm in Chrome, Safari or Firefox, they all behave the same.
I have noticed I can "fix" the issue by breaking the whole document. If I add a character before <!DOCTYPE html>, the href on the css link is pointing at the root again with the leading slash. Is this because of the doctype, the base tag, or some strange combination of the two?
One of the stranger issues I've come across...
By default, SilverStripe leaves off the leading slash on purpose, and uses the base tag to ensure that the links point to the right place. The reason that this was done was to make it easier to build sites that would still work if the site is run in a sub-URL, so that a development site, for example, might be at http://localhost/mysite/.
This is the reason why everything goes to hell in a handbasket if you get rid of the base tag - SilverStripe was built expecting it to be there.
However, it shouldn't be stripping off leading slashes on URLs. The most likely thing that would be doing this is the ContentNegotiator class, and that would lead to different behaviour if you mucked with the doctype.
It used to be on by default but in 2.4 and 3.0 it should be off by default. What version of SilverStripe are you using?
Try appending an extra / at location from where the link is generated.
have you tried base tag?
If this won't work, you can try putting there whole link eg. http://website.com/framework...

Mixing HTML Template with Wordpress PHP File

I'm trying to create a Wordpress template on one of my website pages, http://www.windowblindshadeshutters.com/blog/. The blog is now created, but I want to keep our original existing HTML template header so that it appears like the rest of the website, and then have the Wordpress template PHP file appear as the content on this page.
I started off just copying and pasting our original HTML header code in the top of the Wordpress PHP file, but it doesn't seem to be working right. I'm also wanting to include a doctype at the top, just like the original header, but I'm thinking that you shouldn't do this in a PHP file. My desired result would also require me to mix the original css file with the Wordpress css file, and it just seems like it's not working correctly.
So my question is, "How do I use an existing HTML header (that contains all of the original CSS styling) and insert it into a Wordpress theme effeciently?" Is it as easy as cutting and pasting code, transferring the CSS files, etc?
The original website header can be found at the root domain of the link above.
I'm not entirely sure if I got your question right, so I stand to be corrected: You are intending bring some HTML elements in your main site's header into the blog section's header which is residing in a Wordpress install on your server right?
Well, you're right in the sense that it is copy and paste effort, but I think the more important questions are: from which point on you should be adding those HTML elements in the header.php and what are the things that can or cannot be changed / deleted.
Perhaps a better way to go about this would be for me to tell you the standard things in a header.php and break it down.
<!--the mark up-->
<!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">
<!--the mark up-->
<head>
<!--meta-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--meta-->
<!--document title-->
<title><?php bloginfo('name');?></title>
<!--document title-->
<!--links to scripts and stylesheets-->
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url');?>/style.css" />
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-1.6.1.min.js"></script>
<!--links to scripts and stylesheets-->
</head>
<?php wp_head();?> <!--do not remove-->
THE MARK UP
Okay, so the markup definition in the Doctype is definitely needed in the header.php otherwise the Wordpress theme will not know what it's marked up as. Moreover, the blog section is a Wordpress install on a sub-directory right? Chances are is that it is so it's not gonna be able to grab any information in the root directory where your actual main site is residing in.
META
You can copy the meta description tags or keywords tags from your actual main site and add them to the header.php
DOCUMENT TITLE
You can either choose to hard code and enter the title on the code level or change the blog title in the Wordpress Dashboard and leave it as <?php bloginfo('name');?>. This PHP tag automatically draws whatever is defined as the blog title in the Wordpress Dashboard as the document title. So if the blog title is different from your actual site's title then you will most probably see a discrepancy in that.
LINKS TO SCRIPTS AND STYLESHEETS
If you wish to include the stylesheet from your actual main site that is residing in the root directory, then you will have to change the href to an absolute link that goes there. For e.g. it will look something like <link rel="stylesheet" type="text/css" href="http://www.yourdomain.com/css/style.css" /> rather than <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url');?>/style.css" /> which only links to within your Wordpress install's theme directory. So suppose that you link that external stylesheet from the main site's location to the header.php by means of the method I just mentioned, you can go ahead and paste the necessary HTML content from your actual site's header and the styles should come out right - as long as the classes or ids remain the same.
ADD REQUIRED HTML CONTENT
So once that is all done, go ahead and add any required HTML content from your actual site's header after the <?php wp_head();?> tag. You can add it anywhere you want to and in any order you like to. Just be sure not to mess or overwrite any default template codes that the theme has.
Hope this has answered your question somehow.
You have to edit the header.php file.
After you finished the <header> section, you can start adding the page header.
This will be included in all WP pages / posts.
If you add wrapper start tags in haeder.php, don't forget to end them in footer.php
Read more about this here: http://codex.wordpress.org/Designing_Headers

HTML Base URL and links

I have the following problem:
The URL is http://www.myhomeurl.com/application1/ and the base is:
<base href="http://www.myhomeurl.com/"/>
All resources like images, css and javascript will be at:
http://www.myhomeurl.com/css/myfile.css
http://www.myhomeurl.com/js/myscript.js
http://www.myhomeurl.com/images/img.jpg
BUT, the link will be at "application1", for example:
http://www.myhomeurl.com/application1/page1.html
http://www.myhomeurl.com/application1/page2.html
http://www.myhomeurl.com/application1/page3.html
The question is: How to apply base URL for resources (like css, js, etc) and apply the base/application1 for page links?
Here is a problem when I have:
Click me!
When the user clicks this the page will going to:
http://www.myhomeurl.com/page1.html
and not to:
http://www.myhomeurl.com/application1/page1.html
You could use a base tag and change it so all urls can be relative to the applications base.
<!DOCTYPE HTML>
<html>
<head>
<base href="http://www.myhomeurl.com/application1/" />
</head>
<body>
<!-- content -->
</body>
</html>
Additional information can be found at http://www.w3schools.com/tags/tag_base.asp
edit: w3c spec on base tag http://www.w3.org/TR/html4/struct/links.html#h-12.4 also illustrates how to pull images from other locations.
Change like this on your resources
<link href="./css/myfile.css" rel="stylesheet" type="text/css" />
Not like
<link href="http://www.myhomeurl.com/css/myfile.css" rel="stylesheet" type="text/css" />
And your base it looks like this
<base href="http://www.myhomeurl.com/application1/"/>
Use this varriable in link HTTP_SERVER
define('HTTP_SERVER', 'http://www.myhomeurl.com/application1/');
Click me!
I'm a little late for this question, but I can see none of the answers really do what (I think) you need.
I suggest you to use (as others have already said) a Base Url like this:
<base href="http://www.myhomeurl.com/application1/" />
This way your links will work in the intended way. Then, when you add resources, you only have to go up to the parent directory, like the following:
<link href="../css/myfile.css" rel="stylesheet" type="text/css" />
Or
<style type="text/css">
#import url(../css/myfile.css);
</style>
Note the ../, telling the browser to exit from "application1" directory, going up one step in the file structure.
Hope this helps :)
you should have something like this
root
root/css
root/js
root/files/html1.htm
root/files/htmml2.htm
root will be nothing but /// your website name
http://www.myhomeurl.com
Define two constant one for your css, js resources and one for links and use them across the application:-
define('RESOURCE_URL','http://www.myhomeurl.com/');
define('LINK_URL','http://www.myhomeurl.com/application1');
so that if any change in base url you can look up to these constants only.
I would start all link herd with /and the top directory of the URI. That makes them relative to the domain. Then just put the protocol and domain in the base.
when using base url you should not put www. in it.
Next if your url is mysite.com and your app is located at mysite.com/app then you set your base to be mysite.com/app when you use your example info.html it will look like mysite.com/app/info.html.
You can also use ../app/info.html and it will look like mysite.com/app/info.html

Categories