homepage Welcome to WebmasterWorld Guest from
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

how to 301 redirect pages within folders?
its not working

 7:49 pm on Aug 11, 2012 (gmt 0)

I have items 1-2-3 folders deep that need to be redirected with a 301 but it's not working. Can someone tell me what's wrong with this code:

RewriteRule ^category/keyword/page-title/$ http://www.example.com/category-page-title.html [R=301,L]



 8:25 pm on Aug 11, 2012 (gmt 0)

Nothing is wrong with the code if you want requests for this URL (with or without www, and with or without query strings):
to be redirectly to
and original query string (if present) reattached.


 11:44 pm on Aug 11, 2012 (gmt 0)

Is that your actual, literal code or are you paraphrasing? It may help to give some real-life examples. Using example.com, of course, and showing captures, if any.


 1:37 pm on Aug 12, 2012 (gmt 0)

I was using fake domain/category/keyword names.

I have them working now except for one line of redirects that takes down the whole site and I can't see anything wrong with it. I"ve checked and double checked the old/new files and the spelling is correct. I even retyped the rule to make sure there wasn't strange code in it.

Can someone tell me why this line takes out the whole website? I only changed the domain on this one:

RewriteRule ^services/anesthesia-free-pet-teeth-cleaning-sacramento/$
http://www.example.com/services-anesthesia-free-pet-teeth-cleaning.html [R=301,L]

I get an "internal server error" when this line is in there but everything works fine if I take it back out.


 2:02 pm on Aug 12, 2012 (gmt 0)

Use the Live HTTP Headers extension for Firefox to see if anything else is returned before the server error occurs.


 4:45 pm on Aug 12, 2012 (gmt 0)

Ok, did that. Here is the result after putting that line (a 301 redirect from old page to new) back in htaccess just long enough to test this. Can you tell what's wrong?


GET / HTTP/1.1
Host: www.EXAMPLE.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: __utma=106706774.1114373890.1344777249.1344777249.1344777249.1; __utmz=106706774.1344777249.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

HTTP/1.1 500 Internal Server Error
Date: Sun, 12 Aug 2012 16:37:13 GMT
Server: Apache
Content-Length: 670
Connection: close
Content-Type: text/html; charset=iso-8859-1


 4:57 pm on Aug 12, 2012 (gmt 0)

There's not an external redirect loop, so there's likely an internal rewrite loop.


 8:52 pm on Aug 12, 2012 (gmt 0)

I have several similar redirects renaming files and a handful of 410's and the usual non-www to www for the domain which is last in the list.

Everything works fine except this one redirect. If I put it in the whole site goes down. I checked each of the other redirects one by one and they work fine. This is on a new host too.

Any suggestions as to what I should look for that could be causing a loop?


 11:03 pm on Aug 12, 2012 (gmt 0)

I copied & pasted into a text editor, selected Show Invisible characters and got

RewriteRule ^services/anesthesia-free-pet-teeth-cleaning-sacramento/$
http://www.example.com/services-anesthesia-free-pet-teeth-cleaning.html [R=301,L]

with a hard line break in the middle and a trailing space (LETHAL!) at the end. Are either of those in your real Rewrite, or are they artifacts of your own cut-and-paste into the Forums post?


 2:03 pm on Aug 13, 2012 (gmt 0)

That must have been it as it's working now.

Thanks Lucy

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