I have recently created a directory for a customer of mine. The website is complete however he wants a replicated version of the website so he can test the website and learn how to use it.
To replicate his website fully it will take hours as I will have to change every hyperlink and URL in the website.
As my customer is being a little pushy and wants it done quickly I was wondering if it is posible to create a test website and add a little javascript that will replace his URL each time (until I create a full testing solution?).
For example if it was:
Test
it would replace it to:
Is this posible?
Is it recommended for the time being, until I create a full test solution?
You really should use relative paths so the files interact in relation to each other, regardless of where the files live.
That said, here is a possible quick JS solution you can use for the time being while you make your links relative instead of absolute:
$("a").each(function() {
var href = this.href;
href = href.replace("mydomain.com/", "mydomain.com/test/");
this.href = href;
});
Open up the site files in Notepad++ or any editor that supports file replacement, then do a replace through files (N++ will do this automatically for you), replacing the live URL with a config variable, then set the URL variable as desired for the test site.
Now you have a config variable for the URL, it will be easy if the client wants to change domain or you want to deploy elsewhere.
It is certainly possible to sort out your hyperlinks with javascript, specifically it would be really easy with a framework like jQuery.
$('a').each(Function(e){
e.attr('href', e.attr('href').replace(/http:\/\/mainsite.com/gi, 'http://newsite.com'));
});
Hopefully the URLs in your css files, link hrefs and so on would be relative, otherwise you would need to change those too. At this point a php solution would be more appropriate.
The wget command-line utility has a --convert-links option. If you download a web site using that option, wget will convert the links in such a way that "local browsing works reliably."
Related
I am in the process of creating a website that will eventually be moved to a different domain. Every link on the site currently starts with http://www.mydomain.com/folder. This means that when I move domain I will have to change each and every link. Is there a replacing method of this? Sorry that this is a very basic question, I wasn't quite sure what I was looking for. Thanks for any help.
Firstly; best way is to make it configurable. There should be a global variable:
HTTP_SERVER = 'http://www.mydomain.com/';
and when you want you build a link, you should use:
Link To Folder
But let's get back to your question;
You can use an IDE to search and replace in all of the files in a specific folder. I use Visual Studio which you can choose to search in entire project and replace. But if you want other quick solutions, the best one comes to my mind is Notepad++, you can open a bunch of files and search & replace among them. Another one is Sublime Text which is a great lightweight text-editor / IDE that i use.
I would use an IDE to do a global search and replace across all files in the project.
try declaring a $base_url="www.domain.com/folder" in your connection file which will be included in all pages. so that you can just change the base url there only. and when you want the link call it as $base_url.'/page_name.php';
So basically, what's the difference between the two approach:
<img src="<?php print base_url(); ?>img/test.png" />
<!-- and -->
<img src="/img/test.png" />
I'm having the same result on my website. Might as well remove the URL helper ($this->load->helper('url')) on my controller to cut extra process since they're just the same.
If there is an advantage of adding the helper at all, please let me know.
The difference is if you ever want to put your application in a subdirectory.
If what was / now becomes /application/ all your site root references will break.
It just makes your application free to be installed anywhere and won't require being on the site root.
In my experience with CodeIgniter, using base_url() is a best practice. It ultimately guarantees that your links will be correct (similar to the way adding ../ works when the folder you need is 1 level higher). Also I have had problems in the past with CodeIgniter adding the url in config[base_url] twice if I forgot to put http:// in it. Simple mistake, but it can throw the whole project off. So, basically the difference is that it guarantees the path is the right one, but isn't necessary at all times.
There is no difference if you're using root path of domain.
It's kind like a feature that if you're using it you can migrate easier to any domain or inside directory path.
One more advantage is when you're developing API or RSS feed, the image path or anything else will be written as complete URL so the consumer can use it easily.
I've discovered another thing usin site_url(). It is the only way I found to set a / at the end of my urls.
Eg : will result in http://domaine.tld/controller
On the other hand http://domaine.tld/controller/
hope that helps somebody
I have a typo3 website with no user genrated or dynamic content.
So it is unnecessary to use php and the database.
Is it possible (with php) to clone the hole website and store every page as an html page?
I have only a normal webspace, so i cant install tools like "eAccelerator".
My idea:
- grab every link from the sitemap
- file_get_contents -> store as html
But i think this is not a clean solution? Or?
Thanks in advance!
james
you can use a simple software called HTTRACK., here is the link:
httrack.com
Why you need to use php to copy it? Did you consider using a command line tool like wget? wget allows you to create an "offline" copy of a website which you can of course host somewhere else. Sounds to me exactly like the thing you want to do.
In case you are really stucked to php, you will need an HttpRequest, call the site, parse all links and resources, download the resources, follow the links and do the same again. This is the most simple solution, without any checking for conflicting resources or other stuff which could go wrong.
Sitesucker http://sitesucker.us is an excellent tool you can run from any mac. It works very well, I use it all the time.
But don't forget that by creating a static copy of your site, you will lose your templating functionality. So if you really want to make your website static, I strongly recommend to - at least - put the identical parts of each page into php-includes. Mostly head, page header, footer, navigation. So you're ready for future changes.
If it's just because your TYPO3 is too slow, look at the nc_staticfilecache extension which can speed it up very well.
Using TYPO3 where you need just a simple HTML is a huge overflow, invest in DreamWeaver and code all things 'manually'.
I have a site complete with CMS etc all working under one domain name. It turns out for legal reasons one page on this site has to sit on a different domain name. The page is hooked into the same CMS as the rest of the site (built using codeigniter). I don't want to have to do another installation just for this page.
Is there any simple way to display just this page under a different domain name without taking it out of the current application?
Thanks a lot
You should look at either (in order):
an include()with correct php.ini configuration
a file_get_content() and printing the variable into your page
an <iframe src="yoururl"> wich would be the easy peasy but unsafe way
using the on-purprose curllibrary
using fopen() wich theorically allows distant files to be opened, but based on my experience, it's not that reliable
Look at this site, it seems rather exhaustive regarding your problem.
Try including the file
<?php include 'http://www.domain.com/url/to/file/page.html' ?>
I think what you need here is a symlink, which is something I don't know too much about. My understanding is that the path displayed to the user does not in fact have to have anything to do with where the file is actually stored, meaning you can set this up to have a completely different URL while keeping it as part of your original application.
A simpler thing is doing a redirect...it's one line of code in your .htaccess file and you're good to go.
include is a possible solution depending on the format of the remote page (ie, this won't work very well if the remote page has a full DOM structure, and you're trying to include the remote page within the DOM structure of your CMS page), however more information about that remote page would be needed to help determine if include() alone would be enough.
Regardless, if include() does, work, you must make sure allow_url_include in php.ini is enabled, as by default script execution will terminate when encoutering a remote URL include statement.
I have used AJAX to successfully change the content of a web page. I can include another web page from my domain but the problem I have is making the hyperlinks to work. If the hyperlinks use relative addressing then that will not work relative to the page I am including it in so I was investigating php to parse the html tag as I read it in
I am using the following RegExp /href[\s]?=[\s\"\']+(.*?)[\"\']/im to find the href data but would like a pointer on how I can prefix a relative address.
I would like to replace a link href="./test1/page1.html"
on page http: // foo.bar.com/folder1/info1/data.html
with href="http: // foo.bar.com/folder1/info1/./test1/page1.html" then if I include the the page content of /folder1/info1/data.html in http://foo.bar.com/folder2/faraway/another.html the links on the embedded page will function correctly
I was looking at using the php preg_replace function to do that but have very quickly come unstuck. If I am barking up the wrong tree and there is a more appropriate tool or approach can someone please point me in the right direction ;-). Maybe it can all be down in Javascript?
If you're planning to do much more javascript on the page, you could use JQuery.
function make_absolute(base_path){
$("#embedded a").each(function(){
this.attr("href",
base_path + this.attr("href")
);
});
}
Replace "#embedded" with the id of your embedded page.
This is nearly certainly overkill if you're not going to use javascript for anything else, but if you're planning to make a shiny dynamic ajaxy page, you might look into it.
Bonus:
Doing ajax page loading with JQuery:
$("#embedded").load(page_you_want_to_load)
Taking ABentSpoon's response a step further, your jQuery selector can search for all anchor tags that start with a slash.
$('#embedded a[#href^=/]').each(function() {
$(this).attr('href', baseUrl + $(this).attr('href'));
});
For more help with jQuery selectors, go here.
Why donĀ“t you just use absolute paths?
You guys have certainly helped me out here, many thanks. I think the regular expression I need would be /href[\s]?=[\s\"\']\./is as ABentSpoon pointed out "If it starts with a slash, that's absolute enough for most purposes". However I guess it would be a good excersise to enable reading pages from other sites. Luckily any of the pages I may wish to do this with are on a same site, and on same server.
To pick up on Jeroen comment of just using absolute paths, that is not really an option as there are many pages on this site. Also each page would get addressed differently (DNS) depending on where it'll be accessed from... internally or externally. If you give your links an absolute path you tie ALL of them to having that site DNS name. A problem when you find this changing all too regularly, or for that matter depatments feel the need to change thir subdirectory names, but that's another story. I wish to design this feature to be a little more flexible.
I will certainly read up about jQuery. Looks interesing, it's not something I've played with yet... more learning coming up ;-)
Thanks again for taking the time guys.