Redirecting a Request with Path Information

bnmng.com is mapped to my share on totalchoicehosting‘s servers. But users can still type bnmng.com in the address bar and get redirected to the WordPress blog along with any extra path information. So http://bnmng.com/category/computing/ becomes https://bnmng.wordpress.com/category/computing.

I do this with a simple index.php in the home directory:
index.php
<?php
header('LOCATION: https://bnmng.wordpress.com' . $_SERVER['REQUEST_URI']);
?>

$_SERVER[‘REQUEST_URI’] is everything after the .com. In case the code wraps on your screen, this is just one line of code between the <?php and ?> tags.

But this wouldn’t work unless I ensured that my index.php file would respond to the url with the path info.

To do that, I copied WordPress.org‘s .htaccess file (described here as “genius”, and explained in more detail here), which is found on self-hosted WordPress blogs. This requires Apache’s mod_rewrite.

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

Without this, http://bnmng.com/category/computing/ would simply return a “page not found” error.

That’s all I need to make the redirect. The redirect only occurs if the request is bnmng.com without any path information or bnmng.com with path information that doesn’t correspond to anything on my share. http://bnmng.com/codeexamples, for example, doesn’t get redirected.

This also seems to work for any bnmng.com feeds that people may have subscribed to before I moved bnmng.com from wordpress.com to totalcoicehosting.com. There’s no need to create a feed directory on totalchoicehosting, as I described in an earlier post.

I could have just put a self-hosted blog in my home directory and had a smoother effect without the redirect, but I like the convenience of using WordPress.com’s servers. And if they make a little money with ads on my blog then I’m happy to support them, especially if it doesn’t cost me a dime.

I’m messing around with my domain settings

I’m going to map bnmng.com to another server because I’m so much more than just an erudite blogger, I want to have a place under my URL for such projects as my WordPress themes and by blog reader/sharer if I ever get around to finishing it.

This blog will still be under https://bnmng.wordpress.com, but no longer under bnmng.com.

If you’re one of my countless devoted followers, there’s no need for panic or suicide! I think I can keep the old RSS feeds going by creating a directory on the new server called “feed” and creating an index.php file with the following code:

<?php

$url='https://bnmng.wordpress.com/feed';
if(isset($_SERVER['QUERY_STRING'])) {
$url=$url . '?' . $_SERVER['QUERY_STRING'];
}
$output=file_get_contents($url);
echo $output;
?>

So the RSS feed “http://bnmng.com/feed?cat=262&#8221;, which was mapped to this wordpress blog but will be mapped to the new server, will grab and return the contents from “https://bnmng.wordpress.com/feed?cat=262&#8221;. That should work.

I don’t know if email subscriptions will be affected at all, but I think when I select bnmng.wordpress.com as my primary URL, those will automatically be updated.

Feed Combining: Yahoo Pipes / RSS In Page

On Tina’s old blog, which is still online but not updated since she moved to WordPress, there is a blog roll on her sidebar which shows her blogs in order of most recent update. I can’t find anything that works as well for WordPress. There are various feed combiners for WordPress, but all that I found leave out the name of the blog that the item comes from. And I wanted that to be included.

The best way I found was to use Yahoo Pipes, an online feed combiner from Yahoo. I use the RSS output from Pipes as the source for WordPress’s standard RSS module. Pipes is difficult to understand at first, but it has a video tutorial that should be enough to get a novice started. More advanced operations, like what I’m about to describe, are for people who are more experienced with internet applications.

What I like best about Pipes is the Regex module, which allows me to alter the feed of each item before it gets combined with other feeds. I use the Regex module to put an identifier in the title of each item.

The Feed module gets piped to the Regex module. In the Regex module I select item.title, and replace ^ with the name I want to use followed by a colon and a space. So “The Apocalypse Trade” becomes “Krugman: The Apocalypse Trade”. (^ is Regular Expression syntax for the beginning of a string).

I pipe all of the Regex-modified feeds into a Union module, then pipe the Union module into a Sort module. Finally, the sort gets piped to the Pipe Output. An example of the output is in my main blog.

Yahoo Pipes Editor

To get the RSS feed, I click “Back to My Pipes” and select the pipe I want, then click “View Results”, then “Get as RSS”.

The Regex module has much more capabilities than what I’m using it for and Pipes has more modules than I’ve explored.

Gigaom has a more in depth article.

The interface is a little hard to get use to and Yahoo Pipes intermittently fails to retrieve a feed, but it’s power and versatility make up for any shortcomings.

For a tool that works in wordpress.org and doesn’t require an external combiner, use Rss in page. RSS in Page does not provide a new feed, but it will embed the output of a combined feed into a page or text widget. There’s no graphical interface but if you’re familiar with using shortcodes and can learn some simple formatting commands it’s very versatile.

An improvement, and another use for the safetags function

A while ago I wrote a function which checks HTML snippets and ensures that tags which should be closed are removed unless they are actually closed. For example, if user types

<div style="whatever">Blah Blah

and forgets to close the div tag, then that div tag will be removed. Sure it would be better if the div tag was fixed, but that requires more code. This is good enough for me.

Another use for this function is excerpts. An original article may have all the tags properly closed but the excerpt might have an opening tag with it’s matching tag cut off.

A copy of the function is here.

It is not a validator. It ignores tags like p and br which will work even if not coded properly. You can edit the function to change which tags are allowed.

I used the function to alter Virginia CURE’s website from the original cover-wp theme. For comparison, I found a couple of other websites which use cover-wp: NELA Lives, Hedge Futures, and Marco Luthe. I’m not familiar with these websites, I just looked for websites that use the cover-wp theme. Eventually, any of these websites might disappear, or any of them might change themes, including Virginia CURE. But as I’m writing this they’re good examples. Virginia CURE’s excepts have the paragraphs preserved, the others don’t. The cover-wp theme uses a customized get_the_excerpt function, which in turn calls the built-in php function striptags to remove all of the tags.

Here’s copy of functions.php which I altered from cover-wp. I renamed it functions.txt so it can be viewed. I also made a small change to get_the_excerpt.

If anyone who reads this knows of a better function then I’d be interested. I’m just an amateur hack. But for now, my function works better than anything I found.

I fixed a couple of problems since I first posted it.