Set up 301 Permanent Redirect for clean URLs for WordPress and Other Sites

This is unrelated to Excel, but a neat trick I discovered while moving a website to a new domain. Hope it will help some people out there!
  1. Copy the .htaccess file from the new site to the old website that redirects all clean urls to the index.php file. In this case I just used WordPress’ default .htaccess file, which does the job. (I was moving a WordPress blog.)
  2. Start a new file index.php, and put in the following code in the old site:


Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:".$page);

Basically what we did here is retrieve the part of the URL after the domain name and the slash (/), so if a user requested “”, $_SERVER[‘REQUEST_URI’] would get be “about-us”. There’s a if statement that checks if a / is already included (sometimes it does). If not, it will add one to the URL. All that’s left to do here is just get the header to redirect it to the new domain, and attach $_SERVER[‘REQUEST_URI’] behind it.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>