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

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

Apache Web Server Forum

    
Need Help with Redirects
I'm trying to setup 301 redirects using a .htaccess file & it isn't working
lesterj




msg:4521902
 3:43 pm on Nov 23, 2012 (gmt 0)

Hi,

I've been trying to get some 301 redirects setup for the pages of a site that is moving Joomla install to a Wordpress site using the .htaccess. I'm having trouble getting the redirects to go to the new URLs without adding a file extension to the URL.

Here and example:

The original URL of the page is:
example.com/cms/index.php/Class-Newsletters.html

The new URL of the page is:
example.com/site/for-class-of-2017/class-newsletters/

I set the following for the redirect:

Options +FollowSymLinks
RewriteEngine On
Redirect 301 /cms/index.php/Class-Newsletters.html http://www.example.com/site/for-class-of-2017/class-newsletters/ [R=301,L]


The problem is that the last slash is being removed and the .html is being added to the new URL:
example.com/site/for-class-of-2017/class-newsletters.html

This results in a page not found error.

I've tried adding a $ to the end of the URL in the redirect. This prevents the .html to the new URL, but adds a $ and still ends up with a page not found.

I'm at a loss of how to correct this. Any ideas?

Thanks.

Kurt

 

phranque




msg:4521974
 8:18 pm on Nov 23, 2012 (gmt 0)

welcome to WebmasterWorld, lesterj!

Redirect is a mod_alias directive and you probably want to use mod_rewrite directiives.
do you have any other redirects in your.htaccess?

g1smd




msg:4521976
 8:21 pm on Nov 23, 2012 (gmt 0)

+1

[R=301,L] is not valid syntax with the mod_alias Redirect directive.

Use mod_rewrite syntax: a RewriteRule with full protocol and hostname on the target URL and [R=301,L] flags.

It will give you exactly what you want.

lesterj




msg:4521998
 9:26 pm on Nov 23, 2012 (gmt 0)

Thanks.

Phranque, I'm redirecting about 250 pages. The redirect I gave is just one example. I'm having the same issue with just about all of them.

G1smd, I'm not sure I follow. Could you provide an example?

Thanks.

Kurt

lucy24




msg:4522074
 2:10 am on Nov 24, 2012 (gmt 0)

You can't do what you need to do with mod_alias (Redirect by that name). So the first step is to convert any of your existing redirects from mod_alias format to mod_rewrite [httpd.apache.org] format. If you've got a text editor that does Regular Expressions it can be done almost automatically; I've posted the formulas a couple of times in this forum.

/cms/index.php/Class-Newsletters.html

Eeeeuw! Is that really what the URLs look like? The form that's visible to the public? YUK. No wonder you're moving ;)

Moving from one CMS to another is double-tricky because you're juggling four things:

the old URL
the real location that those old URLs got rewritten to
the new URL
the real location that the new URLs get rewritten to

:: pause for heated argument about usefulness or otherwise of term "real location" in this context ::

You need to:

redirect from old URL to new URL
and then
rewrite from new URL to new location of content

Your WordPress install almost certainly came with a built-in htaccess that takes care of that last rewriting part. In fact I'm sure of it, because RewriteEngine On is a mod_rewrite directive. It has no effect on mod_alias. And, like all boilerplate htaccess files, the WordPress version is weighted down with lines that you can simply throw out. Notably all those <IfModule... envelopes. Just the envelope! Not its content.

But now you've got an extra step. You have to make sure your redirects are safely out of the way before the rewrites start, or else WordPress will be trying to rewrite Joomla URLs and there will be an unspeakable mess.

Do your two sets of URLs, old and new, have any identifying features so you can flag them instantly as one or the other? By "you" I mean "your htaccess". It needs to grab the right ones and skip the wrong ones, and the most efficient way is to do the identifying right in the Rule instead of having to evaluate Conditions every time.

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