The background…
I’m building a new RW site for a client who previously had a Wordpress site. The blog has 150 entries, which we are retaining, but only for archive, SEO and old bookmark purposes.
Initially I thought… Set up a WP site, export the posts from the old site, import to the new one, link to new blog only WP site from new RW site. I set this up and it all worked lovely.
Then Jannis had the idea to convert all the old WP blog posts to Poster2 Markdown files. This way, I didn’t need an install of WP for the sole purpose of a blog archive. Long story short on that one… Jannis came up trumps and sent me 150 odd markdown files which work perfectly in P2.
So I now have a page with Poster2 on it, and all the old WP blogs displayed.
The old WP site was setup a bit weirdly, so the URL to the blog page is…
www.domain.com/blog/
but the URL to each posts is…
www.domain.com/blog-post-name/
Note, no /blog/ folder in the post URL and the trailing slash.
The first bit of replicating the old URL is easy: Poster supports pretty URLs, so I used this in the htaccess…
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule blog/author/(.*) /blog/index.php?author=$1 [L,NC,QSA]
RewriteRule blog/category/(.*) /blog/index.php?category=$1 [L,NC,QSA]
RewriteRule blog/date/(.*) /blog/index.php?date=$1 [L,NC,QSA]
RewriteRule blog/search/(.*) /blog/index.php?search=$1 [L,NC,QSA]
RewriteRule blog/tag/(.*) /blog/index.php?tag=$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule blog/(.*) /blog/index.php?post=$1 [L,NC,QSA]
Now, the Poster2 posts have a nice clean “pretty URL” post, like this…
www.domain.com/blog/blog-post-name
Note the /blog/ bit in the URL and the lack of a trailing slash.
Now the fun, and the bit I need help with. There are two things I need to do…
- Remove the /blog/ bit form the post URL
- Remove the trailing slash from the URL that someone might have bookmarked. So, if the type in (or click a link pointed to)
www.domain.com/blog/blog-post-name/
the URL needs to be changed towww.domain.com/blog/blog-post-name
I’ve had some success with this. I found some code that will indeed pull the /blog/ bit from the URL for blog posts, but it was also pulling it from the blog page URL. So if you typed in www.domain.com/blog you ended up at www.domain.com, the code I got also broke other stuff too.
I also found some code to remove the trailing slash, but it was removing it from all URL’s on the site, which broke all other pages!
I’ve been harassing Jannis all afternoon on this, so I feel it’s time to give the poor guy a break and ask someone else, so here I am!
Any htaccess exports able to help?