The Weebly service is a great place to host your website, but it doesn't let you customize your URLs in any way. Generally, this isn't much of an issue, but I'm all about the details and aesthetics when it comes to my sites, so I want everything to be just right.
In that spirit, I've written a simple little PHP script with an accompanying Apache rewrite rule that will allow you to customize your Weebly URLs in any way you wish.
The technique is pretty straightforward, but if you'd like to know the details then just skip down past the article for a few quick instructions. For everyone else, let's get started!
First, we need to tell Weebly that our custom URLs are available. This is done by adding a single line of code directly into the index page (i.e., the Weebly-generated "welcome" page) for your site:
We'll create the file containing this line in a moment, but first let's take a look at what options we have for customizing our Weebly URLs.
Customizing Your Weebly URLs
Weebly allows you to customize your pages as follows: Site Name : You can change the default "Weebly Click here to begin" title by clicking on the gear icon in your site editor and entering a new title.
The site name can't be used as a custom URL, but changing it is easy and doesn't require any actual code on the page. Page Title : You can change the title of your pages by going to "Layout" -> "Page Attributes" in your site editor and entering a new title for each page. These titles will be used as short titles in the URL when the "Recommended for you" link is selected.
This title can't be used as a custom URL, but changing it is easy and doesn't require any actual code on the page. Path : This option allows you to change the directory structure leading to your site's pages. Go to "Layout" -> "Page Attributes" in your site editor and enter a custom path for each page (e.g., "/our-custom-path/").
This is the only option that allows you to change the URL itself, but it requires some code on the page to work properly. Let's take advantage of this option in a moment.
Customizing Your Weebly URLs on an Existing Site
If you already have a site on Weebly then it's easy to add the code above. Simply go to your site page in your browser, right-click the "welcome" file, and select "View Page Source". This will bring up a text window with your site's source code.
Paste the above line into your site's index page and save your changes – that's all there is to it!
If you're starting from scratch then simply create a new text file on your computer, paste this line into that file, and then upload it to Weebly as "index" for your new site.
Customizing Your Weebly URLs on a New Installation
If you'd rather not muck about with your existing site's URL structure then a decent alternative is to recreate your site from scratch using the code above. Just install Weebly, create a new site, and then use this code in its index page:
This will let you customize your site with a smooth, clean URL structure without having to change anything on an existing site.
Creating the Rewrite Rule in Apache
We'll need to create a new rewrite rule in our Apache configuration so that Weebly will know how to handle these custom URLs. Fortunately, this is pretty straightforward as well:
This is a regular expression that will match any URL starting with "index" and replace it with the contents of your site's "Page Attributes". We wrote this in the form of a rewrite rule so we can use it later to redirect any URLs sent to Apache by Weebly (if you change your site's URL structure then all existing links to your site will be broken).
Customizing Your Weebly URLs in Code
The code above references a "Page Attributes" file that contains the actual text that will be used for each page title. This file can contain either a "page" or a "short-title" – Weebly uses the former when the page is first loaded, and then switches to the latter after some time has passed (this feature makes new pages more attractive than your site's default home page).
Servers like Apache can send files like this pretty easily with the help of an Alias directive:
This will make the "Page Attributes" file available at "http://my-weebly-site.com/pageattr" by default. You can then change that URL to whatever you want using something similar to this in your site's index page:
This allows you to change the page attributes directly from your site – just remember to click "Update Page" before heading back to Apache.
With this line of code, we've configured our site so that every single URL on the site ends with a "/" and an automatically generated title. We can use this technique to create very clean URLs, and we can expand it further to include other site information as well.
Weebly is a great way to get started with your own personal site, and it's even better if you customize the URLs. This allows your site to be used in all sorts of places that require a custom URL, and it also makes links from other sites much easier to use.
Getting Started with Weebly
Weebly is a webapp that you install on your own server – the site then takes care of all the server-side code for you! It all happens in your web browser – there's no need to download or run anything on your computer. It's a great way to get started with your own site, and also has custom domain support for those who want to make their site available on the public web.
Weebly is really easy to use – it has a number of pre-built themes that you can choose from, and you can customize them as you see fit. If you want to start from scratch then feel free to do so – it's all up to you!
Top Blog Posts
- Best URL Shortener: Why You Should Shorten Your Links 1 years ago
- Learn HTML in 12 Minutes 2 years ago
- FOCUS ON YOURSELF NOT OTHERS - Best Motivational Speech 2021 2 years ago
- British English Slang [Advanced Pronunciation Practice] - Reductions & Contractions 2 years ago
- How To Build Your URL Short System (Premium URL Shortening Setup) 2 years ago