Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want my to reach my website's main page when entering an url like:

http://example.com/blog

However, I can't seem to get it to work with a typical rewrite rule:

RewriteRule ^/blog$ /

I'm always taken to my site's 404 page.

Works fine if I specify a specific file (e.g. "/foo.html") instead of "/", but "/index.php" doesnt't work.

How can I make this work?

share|improve this question
    
Do you really want to redirect the browser, or just stay at the same URL but display what would be displayed at the front page? So should the browser address bar show http://example.com/ or http://example.com/blog/? (Use @Jan when you reply in a comment and I get a notification) –  Jan Fabry May 19 '11 at 9:53
    
@Jan It should show example.com/blog if possible, but I don't mind if it doesn't. –  futlib May 19 '11 at 10:06
    
So you want the same information at http://example.com/blog/ and at http://example.com/? Or a static page on the latter? –  Jan Fabry May 19 '11 at 10:13
    
I want the same information. –  futlib May 19 '11 at 12:59

3 Answers 3

up vote 0 down vote accepted

The redirect has to be a 301, not an internal request. Otherwise WordPress will search dor a page named blog.
And you don’t need mod_rewrite.

# Apache 1.3 needs a complete URL
RedirectMatch Permanent ^/blog$ http://example.com/

# Apache 2.x needs just the path
RedirectMatch Permanent ^/blog$ /
share|improve this answer
    
Brilliant, thank you! –  futlib May 19 '11 at 13:00

What would be at example.com? if your using WordPress as CMS and if you want to display your weblogs at example.com/blog just create static front page. See codex page for more information - Creating a Static Front Page

share|improve this answer

You can add an extra rewrite rule to WordPress (not to Apache, via the .htaccess file) to make /blog/ render the latest blog posts:

add_action( 'init', 'wpse17663_init' );
function wpse17663_init()
{
    add_rewrite_rule( 'blog/?$', 'index.php?post_type=post', 'top' );
}

Flush the rewrite rules after you add this code (by visiting the Permalinks page, for example).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.