Friday, May 31, 2013

Custom Redirects in WordPress

Modify WordPress .htaccess file to make redirect from rss_feed to feed


Red line is inserted in original WordPress .htaccess file.

RewriteRule ^rss_feed/?$ /feed/ [L,R=307]

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

# END WordPress

You should use 307 or 302 redirect until your site is ready for production then switch to 301.

If you don't have control over .htaccess file you can render static HTML page instead of WordPress Home Page. Just modify index.php in WordPres root folder like this:
<?php
$hwp_uri = $_SERVER["REQUEST_URI"];
if(substr($hwp_uri,0,-1) == '/') $hwp_uri = substr($hwp_uri,0,-1); 
if($hwp_uri == '/' || $hwp_uri == '/index.php'){
        include('readme.html');
} else {
define('WP_USE_THEMES', true);
 
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
}

No comments:

Post a Comment