Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 Redirect example.com/page2.html to example.com/page2 (php)

Looking for help in this simple 301 redirect.



8:20 pm on Jul 22, 2013 (gmt 0)

Hi! New to this site, but I've been struggling with this for a few weeks. I have changed my site from html to wordpress php. Getting a lot of 404's as the redirects are not going where i need them to. This is what I currently have in my htaccess file.

# 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]

# END WordPress

I am somewhat of a noobie, so I apologize if this is an easy answer.

Appreciate all of your help!


9:40 pm on Jul 22, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

By itself, the boilerplate code doesn't redirect anything. It simply says "If the request is for anything at all whatsoever that doesn't physically exist on the server, dump the problem on index.php and let it deal with things".

You need two things. No, three things, because before anything else you're going to get rid of that <IfModule envelope. Not its contents, just the envelope itself. An <IfModule envelope is never needed in a specific individual htaccess file: you've either got the mod or you haven't. And the envelope is doubly or multiply ridiculous when it pertains to mod_rewrite and any rewrite-based CMS :)

Now then.

FIRST you need to redirect any existing URLs to the desired new form. THEN you need to rewrite those new URLs to serve content from wherever the content lives-- in this case, apparently index.php.

Oops, and a fourth part: You need to make sure your brand-new index.php WordPress page knows how to deal with the old URLs. You can't assume that a CMS-- of any kind-- knows how to handle pages it didn't create itself.

Now, about those 404s. If that really is your entire htaccess, then no redirect is taking place. So the 404 means that, first, the old pages don't physically exist-- at least not in the location where the server is looking-- and the index.php page doesn't know how to deal with a request for "page2.html". That's actually not an htaccess/mod_rewrite issue but a WordPress issue.

And a fifth thing. Putter around this subforum a bit and you'll find lots of long boring lectures on why nobody is going to write your code for you. But we'll hold your hand as you work your way through it.


11:09 pm on Jul 22, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month

Hi LibraRock,

Welcome to WebmasterWorld!

The Library [webmasterworld.com] is actually a great place to find the info you're looking for. There's a few tutorials for beginners in there near the bottom of the page that should walk you through understanding how to construct your own basic rules.


12:39 am on Jul 23, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Your first job is to make a list of the URL requests that have problems.

You'll then need to move quickly to fix this. Ideally this should have been done as part of the site relaunch.

Featured Threads

Hot Threads This Week

Hot Threads This Month