views:

805

answers:

4

Hi guys,

I use Wordpress as a CMS, where the front page is static for the most part and the actual blog part of it has been moved to a new page that uses a custom page template that basically acts as if it were the front page on a standard Wordpress install. It works pretty well but it still has a few bugs. The main one is that pagination will no longer work, Wordpress won't recognize the page URLs that are generated.

So far I've configured Wordpress to display the correct URLs (domain.com/blog/page/2 instead of domain.com/page/2), and I've also gotten it to display a specific page of blog posts via a URL parameter (domain.com/blog?page=N). So basically I'm almost done, I just need to map domain.com/blog/page/N to domain.com/blog?page=N. This would be an easy task if it were just a plain old static site, but Wordpress has it's own URL handling that I believe may be interfering with it - not to mention "blog" isn't an actual URL so it needs to go through the rules twice, once for mapping the blog pagination, and once again so Wordpress can handle the generated URL as it would regularly... I think I may need to use the N or NS flags for the rewrite rules but I just don't know how I would use them

The rule I've come up with:

RewriteRule ^/blog/page/([0-9]+)$ /blog?page=$1

Default Wordpress .htaccess:

RewriteEngine On  
RewriteBase /  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . /index.php [L]

As per some suggestions, I've gotten this for the .htaccess, but it still doesn't recognize it.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule /blog/page/([0-9]+)$ /blog?page=$1 [N,QSA]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

And I'm fairly certain changing the page via the URL parameter does work - I change the number in the URL manually and it does in fact change the page. The web server is LiteSpeed, if that makes any difference

+1  A: 

Try the following

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule /blog/page/([0-9]+)$ /blog?page=$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Mez
/blog/ isn't a folder, it's a Wordpress page (created through the Wordpress backend, stored in the database)
CD Sanchez
sorted that :D my mistake :D
Mez
Hi, thanks for helping :-) I tried putting "RewriteRule ^/blog/page/([0-9]+)$ /blog?page=$1 [N,QSA]" before "RewriteEngine On" but it still wouldn't recognize the URL (returned 404 error)
CD Sanchez
after RewriteEngine On :D
Mez
Does wordpress actually recognise /blog?page=X ?
Mez
Actually, sorry, I put it after (don't know why I said before) but it still doesn't work for some reason. (i'll edit my original question so you can see what I have)
CD Sanchez
does wordpress recognise /blog?page=X ?
Mez
Oddly that didn't work either.. maybe it's a configuration error with the web server. Doesn't redirect to it.. tried some other simple redirections in .htaccess and it still returned a 404
CD Sanchez
This seems strange to me. Without being able to delve into the server, don't think this can be answered easily.
Mez
I guess I'll just try to make it generate the next/previous page URLs using the /blog?page=N format. If I can't find another solution I'll mark yours as the answer later today
CD Sanchez
A: 

Or try

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^blog/page/([0-9]+)$ /blog?page=$1 [NC,N]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [NC,L]
</IfModule>

The NC makes it case insensitive, the N make it reapply the rules, and the L stops the rule processing.

Simeon Pilgrim
Thanks, but it didn't work unfortunately :( Makes perfect sense to me so I don't know why it's not working -- maybe something wrong with LiteSpeed..
CD Sanchez
A: 

Did you ever figure this out, I am 20+ hours searching the web for the answer and no resolve..

bob
I figured it out. I'm sure you did by now too. Hopefully you get this comment :)
CD Sanchez
+1  A: 

I figured it out eventually (a few days after -- I just forgot about this until now). First, make sure you have Wordpress updated. At the time I was using 2.5 or 2.6 but for some reason it didn't work until I updated.

First, create a custom template. You will use this template for your homepage so customize it and all that jazz. Leave the "Main Index" (index.php) template alone -- that template will be used for the blog index page so it needs the WP loop to list your blog posts.

Now, go and create two pages. One for your home page (let's call it "home") and another for your blog (let's call it "blog"). On the "home" page, set the the template to the homepage template you created previously. On the blog page, leave it on the default template -- it will use the "Main Index" template by default.

Now, go into your "Reading" settings and change it to "A static page." For the front page, select the "home" page you created previously. For the posts page, select the "blog" page you created.

That should be it. I had actually tried this beforehand but it did not work so I tried using redirect rules, to no avail. I ended up being an out of date WP install. If you have a sitemap mod installed, make sure you exclude the "home" page so the spiders don't pick up a duplicate of your home page at example.com/home. You can also put it in your robots.txt to be sure.

Once you're done, the root (example.com/) of your domain (assuming you have WP installed there) will point to your "home" page. Your blog page (example.com/blog) will list your posts. Pagination will work as expected (example.com/blog/page/2 etc.).

CD Sanchez