A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearWordPress + mod_rewrite - page 1
User InfoPosts
WordPress + mod_rewrite#1
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]

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

posted date: 2009-04-06 13:17:00

Re: WordPress + mod_rewrite#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-06 13:17:01

Re: WordPress + mod_rewrite#3
Try the following<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule /blog/page/([0-9]+)$ /blog?page=$1 [R=301]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>

posted date: 2009-04-06 13:22:00

Re: WordPress + mod_rewrite#4
/blog/ isn't a folder, it's a Wordpress page (created through the Wordpress backend, stored in the database)

posted date: 2009-04-06 13:26:00

Re: WordPress + mod_rewrite#5
sorted that :D my mistake :D

posted date: 2009-04-06 13:31:00

Re: WordPress + mod_rewrite#6
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)

posted date: 2009-04-06 13:43:00

Re: WordPress + mod_rewrite#7
after RewriteEngine On :D

posted date: 2009-04-06 13:50:00

Re: WordPress + mod_rewrite#8
Does wordpress actually recognise /blog?page=X ?

posted date: 2009-04-06 13:51:00

Re: WordPress + mod_rewrite#9
Or try<IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^blog/page/([0-9]+)$ /blog?page=$1 [NC,N]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /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.

posted date: 2009-04-06 14:30:00

Re: WordPress + mod_rewrite#10
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..

posted date: 2009-04-06 14:44:00

Re: WordPress + mod_rewrite#11
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.).

posted date: 2009-12-15 13:55:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.