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)

New User

joined:July 22, 2013
votes: 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 July 22, 2013 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
votes: 552

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 July 22, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:July 19, 2013
votes: 0

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 July 23, 2013 (gmt 0)

Senior Member

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

joined:July 3, 2002
votes: 0

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.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members