WordPress Blog URL Spelling .htaccess Tutorial

WordPress Blog URL Spelling .htaccess Tutorial

WordPress Blog URL Spelling .htaccess Tutorial

Don’t want to get too “royal” here, but …

When one deals with Apache web servers one finds oneself getting interested in .htaccess for breakfast, lunch and tea.

Yes, for us, getting to know the “.htaccess” wooooorrrrlllddd is a potential pathway to software functionality that is “extremely cut through” but at the same time has quite a bit of a learning curve associated with it. Then there is the danger of a powerful tool like “.htaccess” you might damage a web server by allowing through user access hackers are interested in.

When we changed our WordPress blog from version 3.0.3 to 4.1.1 we opted for the Document Root of that 4.1.1 blog be at the Linux directory corresponding to the URL …

HTTP://www.rjmprogramming.com.au/ITblog/

… because we hoped you’d get “IT” … “I.T.” … “information technology” … huh?!

Well, some days later we realized that really we are asking a lot of users not relying on search engines to get to the URLs of a website, to find this blog when it might be more instinctive to expect …

HTTP://www.rjmprogramming.com.au/itblog/

… or …

HTTP://www.rjmprogramming.com.au/ITBLOG/

Well, we were not overly ambitious here, just wanting a mapping system on our Apache web server to equate the “prefix” (or “starts to”) to URLs above to …

HTTP://www.rjmprogramming.com.au/ITblog/

Queue “.htaccess” usage if “Apache” is your brand (of web server). It’s (potentially, given some learning effort) brilliant!

Think URL “misspellings if you will, our “.htaccess” and “mod_rewrite” based solution is in two parts …

itblog ITBLOG
.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ITblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ITblog/index.php [L]
</IfModule>

# END WordPress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ITblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ITblog/index.php [L]
</IfModule>

# END WordPress
index.php

<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( str_replace("/itblog", "/ITblog", dirname( __FILE__ )) . '/wp-blog-header.php' );

<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( str_replace("/itblog", "/ITblog", dirname( __FILE__ )) . '/wp-blog-header.php' );

… allowing URLs such as …


https://www.rjmprogramming.com.au/itblog/html-marquee-and-meter-and-input-date-css-tutorial/

… to work, effectively mapping themselves to a URL …


https://www.rjmprogramming.com.au/ITblog/html-marquee-and-meter-and-input-date-css-tutorial/

… via an Apache “.htaccess” and “mod_rewrite” based (URL mapping) solution.

Good inhouse background reading is available at WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial.


Previous relevant WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial is shown below.

WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial

WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial

As we pick up from yesterday’s WordPress Blog Posting Title Regular Expression Search Primer Tutorial with explaining the functionality behind our new WordPress Blog Title Regular Expression Search functionality you can …

  • take a peak at the URL created during its use on the way .. via (header.php’s Javascript HTML select element onchange event logic) …

    function asksr() {
    var av=prompt('Blog Posting Titles matching Regular Expression?', document.getElementById('s').value);
    if (av != null) {
    if (av != '') {
    if (av.substring(0,1) == '.') {
    location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(String.fromCharCode(92) + av);
    } else {
    location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(av);
    }
    }
    }
    }

    … to showing the top of the page HTML select element dropdown … or, be a smart Alec and …
  • take a peak at the second last word of today’s blog posting title

… to get the hint that, today, we have on our hands an example of the use of an Apache web server .htaccess approach to URL processing and navigation control.

The use of .htaccess files in Apache web server environments is quite a big subject, and for more far reaching detail than what we provide today, we would like to direct you towards this useful webpage (and while you are at it, read about our upgrade from WordPress 3.0.3 to WordPress 4.1.1 and some .htaccess work via the blog posting thread ending at WordPress Upgrade Crontab Curl Tutorial). What can you do within a subject area you want to learn? Stay informed, read, consult or … take leads from others, and by so doing, know more the specifics of what you need to read and research, we hope?! So it was with us, taking leads off something we’d done earlier taking leads off what WordPress had shown us was possible in that ‘earlier on’ period.

We find .htaccess work very satisfying, as it is making URLs look less ‘manufactured’ … though, today, it must be admitted, an interim URL we use obfuscates that elegance a fair bit. Nonetheless, having these ‘magical’ URLs with no ? nor & (quite often) doing these strange things happens (with .htaccess work) because … the .htaccess mapped URL’s PHP or HTML code is passed the original URL and it behoves that mapped code to make use of that fact … in other words, the address bar URL will still be the elegant non-?-& URL that the PHP or HTML’s document.URL sees and can ‘chameleon fashion’ change its guise, according to … and we go and ‘change the guise’ to a self recalling arrangement of a URL that does contain a ? and is thus available to the PHP we write in the global variable $_GET[‘pm’] as per (hint: mapper.php’s) code snippet …


if (isset($_GET['pm'])) { // recall scenario
// populate the HTML select element dropdown via $_GET['pm'] ... rest assured, PHP's eregi is used in this logic
} else { // got here via .htaccess in //www.rjmprogramming.com.au/itblog/match/ web server directory
// recall yourself via location.href='//www.rjmprogramming.com.au/itblog/match/mapper.php?pm=' + document.URL.replace(''//www.rjmprogramming.com.au/itblog/match/', '');
}

Okay, so did you “take a peak at the URL created during its use on the way to showing the top of the page HTML select element dropdown”? If so you’d have found a sequence of URLs, the first two really hard to get a glimpse of …

  1. //www.rjmprogramming.com.au/itblog/match/Python
  2. //www.rjmprogramming.com.au/itblog/match/mapper.php
  3. //www.rjmprogramming.com.au/itblog/match/mapper.php?pm=Python

… because it all happens so fast, and we’ve helped you out in today’s tutorial picture imagining it happening. But what happens? Well, the URL’s //www.rjmprogramming.com.au/itblog/match/ underlying web server directory has a special file, at least to Apache web servers, and it is called .htaccess and for the scenario above it comprises …


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/match/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /itblog/match/mapper.php [L]
</IfModule>

# END WordPress

… about which you need to see that Apache’s mod_rewrite module needs to be active for this .htaccess file to be noticed and that “RewriteRule . /itblog/match/mapper.php [L]” is the bit that spurs the …

… mapping taking place, and is the doing of the .htaccess file, while the rest happens within our homegrown mapper.php where its navigational progression …

… can only feasibly be guessed at by mapper.php because the previous “//www.rjmprogramming.com.au/itblog/match/Python” URL is available to it in the Javascript DOM client “document.URL” global … cute, huh?! And, that being the case we know to construct HTML select element dropdown contents based on “Python” and to populate an HTML iframe below with the landing page of the blog, awaiting any user specified instructions.

You may well reason that you don’t have to involve .htaccess Apache methods to get this job done, and you’d be right, but the topic can be extremely useful regarding Apache web servers, like we have at www.rjmprogramming.com.au … and so we thought we’d show you some details here, and we hope you like it.

Did you know?

Were you a blog reader here when we introduced WordPress version 4.1.1 into the equation? Do you recall us making URLs …

… “equate” to the same web (blog) application webpage? Please read the “Did you know?” of WordPress Upgrade Implications Tutorial for more information here, but the gist of making this happen was to place into //www.rjmprogramming.com.au/itblog/ URL’s underlying web server directory the .htaccess file as below …


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ITblog/index.php [L]
</IfModule>

# END WordPress

… which amounts to a very similar concept to today’s mapper.php for our Blog Post Title Regular Expression Searches scenario, and is a lesson in how individual web server directories can have tailored .htaccess functionalities.


Previous relevant WordPress Blog Posting Title Regular Expression Search Primer Tutorial is shown below.

WordPress Blog Posting Title Regular Expression Search Primer Tutorial

WordPress Blog Posting Title Regular Expression Search Primer Tutorial

One of our chief aims with this blog is to send the user off on a themed ‘thread’ of inquiry. What came, by default with our WordPress TwentyTen themed blog was to categorize via …

  • Category
  • Tag
  • Search (string)

… and then … some time back … sun comes up, sun goes down x 100’s … we allowed a Search (string) arrangement within one of the other two ‘parent’ searches … and today … da da da da da, da da da … we allow a Regular Expression search of Blog Posting titles … because …

  • it fits in quite nicely with our long-winded blog posting title regime, which has been designed to tell it like it is … but not great for SEO (you should be warned) … and …
  • we’ve always felt that an exploration of a topic like “Python”, for example, will not necessarily fit into a “Category” nor necessarily even a “Tag” scenario nearly as well, for us, as to allow a (Regular Expression) search of Blog Posting Titles for “Python”

… as well as the cute feature that, because it is using PHP Regular Expressions via the eregi method, you could narrow the search via ^Python as an example to ensure Blog Posting Titles have to start with “Python”.

There is a dual purpose to this work, but we’ll just be discussing the “interface” to the WordPress blog today, and detail something else regarding it tomorrow. So for today, we add a new HTML input element type=checkbox next to the blog’s Search input textbox, and off whatever might have been entered as text into that field as the default string for a Javascript prompt window asking of what Blog Posting Title Regular Expression Search they want to perform, and this sends the user to a new webpage consisting of …

  1. one HTML select element dropdown of matching Blog Posting Titles … under which is …
  2. one HTML iframe element initially showing the blog’s landing page but ready to be repopulated via any choice the user makes regarding the HTML select element dropdown above … like a television with “top” control

That HTML input element type=checkbox (that you can see in today’s tutorial picture) is coded (in … you guessed it … good ol’ header.php) as below …


<input title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();" type='checkbox' id='scbtype' value='Title RE'></input><a style='cursor:pointer;text-decoration:underline;' title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();">Title RE</a>

We’ll be taking off from this point explaining more about the architecture behind this functionality tomorrow. But you being here, up at the Search input box you can try out what we mean, to see all this in action. And it may be worth considering … a “Regular Expression” each day keeps you Regular … yes, you heard it first here, folks!

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>