homepage Welcome to WebmasterWorld Guest from 23.20.77.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 Redirect example.com/page2.html to example.com/page2 (php)
Looking for help in this simple 301 redirect.
LibraRock




msg:4595478
 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]
</IfModule>

# END WordPress


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

Appreciate all of your help!

 

lucy24




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

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.

JD_Toims




msg:4595539
 11:09 pm on Jul 22, 2013 (gmt 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.

g1smd




msg:4595563
 12:39 am on Jul 23, 2013 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved